/**
 * 诊断录入
 * JYW
 */
import React from 'react';
import { Card, Table, Input, Select, Col, Checkbox, Tabs, DatePicker, Button, Icon, Divider, message, Tree, Menu, Radio, Tooltip, Dropdown, AutoComplete } from 'antd';
import Message from '../../common/ModalMessage.jsx';
import { Util } from 'tools/index';
import { $http } from 'containers/config/https';
import AddDiagTemplateModal from './AddDiagTemplateModal';
import ShowCommonTableModal from './ShowCommonTableModal';
import ColumnAuthoritysModel from '../../columnAuthority/ColumnAuthoritysModel'
import InfectiousModel from '../../nurse/InfectiousDisease/InfectiousModel.jsx';
import moment from 'moment';
import store from 'store';
import '../style/index.less';

const TabPane = Tabs.TabPane;
const Option = Select.Option;
const { TreeNode } = Tree;
const SubMenu = Menu.SubMenu;
const doctorOrder = require('../image/img/icon_doctororder.png');
let recordData, userData;
var scrollCount = 0;

class DiagnosisStepPage extends React.Component {
	constructor(props) {
		super(props)
		userData = JSON.parse(sessionStorage.getItem('userData'));
		recordData = JSON.parse(sessionStorage.getItem('patientData'));
		if (!recordData) {
			recordData = JSON.parse(sessionStorage.getItem('recordData'));
		}
		this.state = {
			selectIndex: 0,//当前选中行
			dataSource: [],
			typeData: [], //诊断类型
			statusData: [],//诊断备注
			catData: [], //诊断级别
			diagData: [],//诊断基础数据
			diagCategory: [], //诊断类别
			conditionData: [],    //病情
			total: 0,
			page: 1,
			pageSize: 50,
			current: 1,
			ids: [],
			showDialog: false,
			userData,
			selectData: [],
			searchData: {},
			changename: '',
			changeValue: '',
			recordData: recordData,
			indexTable: '',
			visible: false,
			visStatus: false,
			CMark: "N",
			mainDiag: "N",
			diagTypeDefID: "",
			diagCatDefID: "",
			diagStatusDefID: "",
			editData: [],
			admType: "",
			historyDiag: [],
			medicalType: [],
			systolic: "",  //收缩压
			diastolic: "", //舒张压
			patHeight: "", //身高
			patWeight: "", //体重
			pulse: '', //脉搏
			temperature: '', // 体温
			breath: '', //呼吸
			medicalTypeID: "",
			diagTemplate: [],  //保存到模板的诊断
			templetType: [],
			templetTreeData: [],
			nodeId: [], //诊断模板选中项
			templateDesc: "",
			activityTabs: "0",
			diagColumns: [],
			diagColumnsWidth: '1000px',
			moduleStatus: false,
			radioValue: 1,
			EN: {},
			CN: {},
			search: "",
			measureFlag: '',
			SyndromeTypeColumns: [],
			dialogColumns: [],
			ICDColumns: [],  // 是否需测血压
			modelHeight: 330,
			regexData: [],
			selectedMode: "N",
			diseaseID: '',   // 传染病
			conditionDefID: '', // 默认病情
			admInfo: {},
			measureAge: '',
			checked: true,
			expandedKeys: [],
			tableConfigFlag: '', //表头配置
			currentLocData: {
				locID: userData?.locID,
				locDesc: userData?.locDesc
			},
			userLoginLoc: [], // 科室下拉数据
			loading: false,
			mainDiagConfig: 'N'
		}
		this.loadListener = this.keyDownElement.bind(this);
		this.myRef1 = React.createRef();
		this.myRef2 = React.createRef();
		this.myRef3 = React.createRef();
		this.myRef4 = React.createRef();
		this.myRef5 = React.createRef();
		this.myRef6 = React.createRef();
		this.myRef7 = React.createRef();
	}

	componentDidMount() {
		this.loadWorkstationSetting()//获取医生站配置（医嘱套默认）
		// this.initData();
		this.props.onRef(this)
		this.loadData();
		this.getTableConfig();     //获取表头配置
		//this.loadColumn();
		//this.loadDiagnosisColumn();
		this.loadICDColumn();
		this.loadSyndromesColumn();
		message.config({ top: 400, duration: 3 });
		this.ifNeedMeasuringBP();
		this.loadEndReceiveOfDisableBtn()
		this.loadConfigAssessmentSheet()//获取门诊挂号评估单
	}

	loadWorkstationSetting() {
		// var params = {
		//     params: [{
		//         hospID: this.state.userData.hospID,
		//         locID: this.state.userData.locID,
		//         userID: this.state.userData.userID,
		//     }]
		// }
		// $http.post('urlDeault', this, {
		//     code: "01040230",
		//     data: params,
		//     success: function (res) {
		//         if (res.errorCode == '0') {
		//             this.setState({
		//                 radioValue: !Util.isEmpty(res.result) ? (Number(res.result.DiagTemplate)) : '',
		//             }, () => {
		this.initTempletTreeData('Y');
		//             })
		//         }
		//     }
		// });
	}

	/* @GJG
	 * 添加表头配置，展示医保
	 */
	getTableConfig() {
		var params = {
			params: [{}],
		}
		$http.post('urlDeault', this, {
			code: "03050280",
			data: params,
			success: function (res) {
				/**
				 * @ByShizi: 不同诊断类型是否需要选择主诊断【医生站配置-诊断类型必须勾选主诊断】
				 * 需求: #1149
				 * Create 2023-02-23
				 * */
				this.state.mainDiagConfig = res?.mainDiagConfig || 'N';
				if (res.errorCode == '0') {
					if (res.result === 'Y') {
						this.setState({
							tableConfigFlag: res.result,
						}, () => {
							this.loadColumn();
							this.loadDiagnosisColumn();
						})
					} else {
						this.loadColumn();
						this.loadDiagnosisColumn();
					}
				} else {
					this.loadColumn();
					this.loadDiagnosisColumn();
				}
			}
		});
	}

	loadConfigAssessmentSheet() {
		var params = {
			params: [{
				hospID: this.state.userData.hospID,
				userID: this.state.userData.userID,
				locID: this.state.userData.locID,
				admID: !Util.isEmpty(this.state.recordData) ? this.state.recordData.admID : ''
			}]
		}
		$http.post('urlDeault', this, {
			code: "03040032",
			data: params,
			success: function (res) {
				if (res.errorCode == '0') {
					this.setState({
						assmentSheetData: res.result,
						activeKey: !Util.isEmpty(res.result) ? res.result[0].id : ''
					})
				}
			}
		});
	}

	loadEndReceiveOfDisableBtn() {
		var params = {
			params: [{
				admID: recordData ? recordData.admID : '',
				hospID: userData.hospID,
				userID: userData.userID,
				locID: userData.locID,
			}]
		}
		$http.post('urlDeault', this, {
			code: "03100124",
			data: params,
			success: (res) => {
				if (res.errorCode == '0') {
					this.setState({
						disBtn: res.result
					})
				}
			}
		})
	}

	// 下拉框选中事件
	handleOnSelect = (num, code, value) => {
		if (code != '') {
			let data = {
				params: [{
					code,
					value
				}]
			};
			$http.post('urlDeault', this, {
				code: "04040021",
				data: data,
				success: function (res) {
					if (+res.errorCode === 0) {
						let ret = res.result
						if (ret == 1) {
							if (code == 'SBP') {
								message.warning('患者收缩压低于正常值!', this.state.userData && this.state.userData.messageTime)
							}
							if (code == 'DBP') {
								message.warning('患者舒张压低于正常值!', this.state.userData && this.state.userData.messageTime)
							}
						}
						if (ret == 2) {
							if (code == 'SBP') {
								message.warning('患者收缩压高于正常值!', this.state.userData && this.state.userData.messageTime)
							}
							if (code == 'DBP') {
								message.warning('患者舒张压高于正常值!', this.state.userData && this.state.userData.messageTime)
							}
						}
					}
				},
				error: function (error) {
					message.error('失败：' + error);
				}
			});
		}

		let ref = "myRef" + (num + 1);
		if (this[ref]) {
			setTimeout(() => {
				this[ref].current.focus();
			}, 300)
		}
		// switch (num) {
		//     case 1:
		//         setTimeout(() => {
		//             this.myRef2.current.focus();
		//         }, 300)
		//         break;
		//     case 2:
		//         setTimeout(() => {
		//             this.myRef3.current.focus();
		//         }, 300)
		//         break;
		//     case 3:
		//         setTimeout(() => {
		//             this.myRef4.current.focus();
		//         }, 300)
		//         break;
		//     case 4:
		//         setTimeout(() => {
		//             this.myRef5.current.focus();
		//         }, 300)
		//         break;
		// }
	}

	onRef = (ref) => {
		this.child = ref;
	}

	onInfectiousRef = (ref) => {
		this.childInfectious = ref
	}

	componentWillUnmount() {
		// 组件销毁前将静止让setState修改state的状态
		this.setState = (state, callback) => { return; }
	}

	componentDidUpdate() {
		//获取当前添加的数据作为未保存数据的标识，用于step切换的校验
		let findFlag = false;
		let editData = this.state.editData;
		let dataSource = this.state.dataSource;
		for (var i = 0; i < editData.length; i++) {
			let diag = dataSource[editData[i]];
			if (!Util.isEmpty(diag)) {
				if (!(Util.isEmpty(diag.diagID)) || (!Util.isEmpty(diag.descripts)) || (!Util.isEmpty(diag.ICDID))) {
					findFlag = true;
				}
			}
		}
		var { componentRouter } = this.props;
		componentRouter && componentRouter(findFlag, '2')
	}

	keyDownElement(e) {
		if (this.state.visible) {
			if (e.keyCode == '13') {
				this.setState({
					newIndex: 0
				})
			}
		}
	}

	loadDiagnosisColumn = () => {
		let data = {
			params: [{
				compontName: "DiagnosisStepPage",
				type: "C",
				reactCode: ['DiagnosisStepPage']
			}]
		}
		$http.post('urlDeault', this, {
			code: "01040073",
			data: data,
			success: (res) => {
				if (res.errorCode == 0) {
					var columnsSource = []
					let columns = res.result.C;
					if (columns) {
						for (let i = 0; i < columns.length; i++) {
							// column[i].title = column[i].enDescripts
							if (columns[i].dataIndex == 'diagDesc') {
								columnsSource.push({
									title: this.state.userData.language == 'EN' ? <span>{columns[i].enDescripts}
										<span style={{ marginLeft: 20 }}><span style={{ color: '#007AFF' }}>眼科：</span>
											<Checkbox defaultChecked={this.state.checked} value={this.state.checked} onChange={this.handleChangeChecked.bind(this, 'checked')} /></span>
									</span> :
										<span> {columns[i].descripts}<span style={{ marginLeft: 20 }}><span style={{ color: '#007AFF' }}>眼科：</span>
											<Checkbox defaultChecked={this.state.checked} value={this.state.checked} onChange={this.handleChangeChecked.bind(this, 'checked')} /></span></span>,

									dataIndex: columns[i].dataIndex,
									width: columns[i].width,
									align: columns[i].align
								})
							} else {
								columnsSource.push({
									title: this.state.userData.language == 'EN' ? columns[i].enDescripts : columns[i].descripts,
									dataIndex: columns[i].dataIndex,
									width: columns[i].width,
									align: columns[i].align
								})
							}
						}
					}
					if (this.state.tableConfigFlag === 'Y') {
						columnsSource.push({
							title: '医保代码',
							dataIndex: 'insuCode',
							width: 80,
							align: 'left',
						});
						columnsSource.push({
							title: '医保描述',
							dataIndex: 'insuDesc',
							width: 200,
							align: 'left',
						})
					}
					this.setState({
						dialogColumns: columnsSource
					});
				}
			}
		})
	}

	handleChangeChecked(name, e) {
		this.setState({
			[name]: e.target.checked
		}, () => {
			this.loadSelectData('', 1)
		})
	}

	loadICDColumn = () => {
		let data = {
			params: [{
				compontName: "IDCColunm",
				type: "C",
				reactCode: ['IDCColunm']
			}]
		}
		$http.post('urlDeault', this, {
			code: "01040073",
			data: data,
			success: (res) => {
				if (res.errorCode == 0) {
					let column = res.result.C;
					if (userData.language == 'EN') {
						for (let i = 0; i < column.length; i++) {
							column[i].title = column[i].enDescripts
						}
					}
					this.setState({
						ICDColumns: column
					})
				}
			}
		})
	}

	loadSyndromesColumn = () => {
		let data = {
			params: [{
				compontName: "SyndromesColunm",
				type: "C",
				reactCode: ['SyndromesColunm']
			}]
		}
		$http.post('urlDeault', this, {
			code: "01040073",
			data: data,
			success: (res) => {
				let column = res.result.C;
				if (res.errorCode == 0) {
					if (userData.language == 'EN') {
						for (let i = 0; i < column.length; i++) {
							column[i].title = column[i].enDescripts
						}
					}
					this.setState({
						SyndromeTypeColumns: column
					})
				}
			}
		})
	}

	//查询列头数据
	loadColumn = () => {
		let data = {
			params: [{
				compontName: "DiagTable",
				type: "C",
				reactCode: ['DiagTable']
			}]
		}
		$http.post('urlDeault', this, {
			code: "01040073",
			data: data,
			success: (res) => {
				if (+res.errorCode === 0) {
					var columns = this.getCurrentColumns(res.result?.C || []);
					if (columns && columns.length > 0) {
						columns = columns.map(item => {
							let align = item?.align || 'center';
							return {
								...item,
								title: userData.language != 'EN' ? (userData.language != 'EN' ? item.title : item.enDescripts) : item.enDescripts,
								render: (text, data, index) => {
									if (item.dataIndex == 'mark') {
										return (Util.isEmpty(data.id) && (data.editable)) ?
											<Select
												style={{ width: '98%', }} value={data.diagCMarkID || this.state.CMark}
												onChange={this.onCMarkChange.bind(this, index)}
											>
												{
													this.state.diagCategory && this.state.diagCategory.map((item) => {
														return (<Option key={item.code + ""} value={item.code}>{item.descripts}</Option>)
													})
												}
											</Select> : data.diagCMark
									} else if (item.dataIndex == 'diagType') { // 诊断类型
										return ((Util.isEmpty(data.id)) || (data.editable)) && (data.diagCMarkID != "Z") ? <Select style={{ width: '98%' }} value={data.diagTypeID || this.state.diagTypeDefID} onChange={this.onDiagTypeChange.bind(this, index)} >
											{
												this.state.typeData && this.state.typeData.map((item) => {
													return (<Option key={item.id + ""} value={item.id} code={item.code}>{item.descripts}</Option>)
												})
											}</Select> : data.diagTypeDesc
									} else if (item.dataIndex == 'diagDesc') { // 诊断名称
										let refName = "diagDesc" + index;
										this[refName] = React.createRef();
										return ((data.id) && (!data.editable)) ? <div style={{ textAlign: align, width: "100%" }}>{data.diagDesc}</div> :
											<Input style={{ width: '99%' }}
												id={"diagDesc-input" + index}
												ref={this[refName]} disabled={this.state.disBtn == 'N'}
												onKeyDown={this.showCommonTableModal.bind(this, index, data, "diagDesc")} allowClear={true}
												autoFocus
												onFocus={this.onDiagDescFocus.bind(this, index)}
												value={data.diagDesc || ''}
												onChange={this.handleSearchInput.bind(this, 'diagDesc', index, data)}
											/>
									} else if (item.dataIndex == 'ICDDesc') {
										return ((Util.isEmpty(data.id)) || (data.editable)) ?
											<Input style={{ width: '99%' }} id={"ICDDesc-input" + index}
												onKeyDown={this.showCommonTableModal.bind(this, index, data, "ICDDesc")} allowClear={true}
												value={data.ICDDesc || ''}
												onChange={this.handleSearchInput.bind(this, 'ICDDesc', index, data)}
											/> : <div style={{ textAlign: align, width: "100%" }}>{data.ICDDesc}</div>
									} else if (item.dataIndex == 'mainDiag') {
										return <Checkbox onChange={this.onMainDiagChange.bind(this, data, index)} checked={data.mainDiagID == "Y"}
											disabled={((!data.editable) || (data.mainFlag != "Y"))}>
										</Checkbox>
									} else if (item.dataIndex == 'descripts') {
										return ((Util.isEmpty(data.id)) || (data.editable)) && (data.diagCMarkID != "Z") ?
											<Input key="descripts" autoFocus={!Util.isEmpty(data.id)} style={{ width: '98%' }} onPressEnter={this.onDescriptsEnter} value={data.descripts} onChange={this.onDescChange.bind(this, index)} /> :
											<div style={{ textAlign: align, width: "100%" }}>{data.descripts}</div>
									} else if (item.dataIndex == 'onsetDate') {
										return ((Util.isEmpty(data.id)) || (data.editable)) && (data.diagCMarkID != "Z") ? <DatePicker
											onChange={this.onsetDateChange.bind(this, index)}
											value={data.onsetDate ? moment(data.onsetDate, 'YYYY-MM-DD') : moment(new Date(), 'YYYY-MM-DD')}
											disabledDate={(curDate) => {
												return curDate && curDate > moment().endOf('day');
											}}
										>
										</DatePicker> : data.onsetDate
									} else if (item.dataIndex == 'condition') {
										return (Util.isEmpty(data.id)) || (data.editable) ? <Select style={{ width: '98%' }} value={data.conditionID || this.state.conditionDefID} onChange={this.onConditionChange.bind(this, index)} >
											{
												this.state.conditionData && this.state.conditionData.map((item) => {
													return (<Option key={item.id + ""} value={item.id}>{item.descripts}</Option>)
												})
											}</Select> : data.conditionDesc
									} else if (item.dataIndex == 'eyePart') {
										return (Util.isEmpty(data.id)) || (data.editable) ? <Select style={{ width: '98%' }} value={data.eyePartID || this.state.eyePartID}
											onChange={this.onEyePartChange.bind(this, index)} allowClear>
											{
												this.state.eyePart && this.state.eyePart.map((item) => {
													return (<Option key={item.id + ""} value={item.id}>{item.descripts}</Option>)
												})
											}</Select> : data.eyePartDesc
									} else if (item.dataIndex == 'disCondition') {
										return (Util.isEmpty(data.id)) || (data.editable) ? <Select allowClear style={{ width: '98%' }} value={data.disConditionID || this.state.disConditionID}
											onChange={this.onChangeCommonSelect.bind(this, 'disConditionID', index)} >
											{
												this.state.disCondition && this.state.disCondition.map((item) => {
													return (<Option key={item.id + ""} value={item.id}>{item.descripts}</Option>)
												})
											}</Select> : data.disConditionDesc
									} else if (item.dataIndex == 'disease') {
										return (Util.isEmpty(data.id)) || (data.editable) ? <Select allowClear style={{ width: '98%' }} value={data.diseasesID || this.state.diseasesID} onChange={this.onDiseaseChange.bind(this, index)} >
											{
												this.state.disease && this.state.disease.map((item) => {
													return (<Option key={item.id + ""} value={item.id}>{item.descripts}</Option>)
												})
											}</Select> : data.diseasesDesc
									}
									else {
										return text;
									}
								}
							}

						})
						this.setState({
							diagColumns: columns,
							diagColumnsWidth: res.totalWidth,
						})
					}
					this.setState({
						EN: res.result.language.EN,
						CN: res.result.language.CN
					})
				}
			}
		})
	}

	// 医生站配置 - 医嘱列表显示医保信息
	getCurrentColumns = (columns) => {
		let { tableConfigFlag } = this.state;
		return columns && columns.filter((item) => {
			if (tableConfigFlag !== 'Y' && (item.dataIndex === 'insuCode' || item.dataIndex === 'insuDesc')) {
				return false;
			} else {
				return true;
			}
		})
	}

	// 中英文切换
	display(name) {
		return this.state.userData.language != 'EN' ? (this.state.CN[name] && this.state.CN[name]['descripts'] ? this.state.CN[name]['descripts'] : '') : (this.state.CN[name] && this.state.EN[name]['descripts'] ? this.state.EN[name]['descripts'] : '')
	}

	// 中英文切换
	displaymessage(name) {
		return this.state.userData.language != 'EN' ? (this.state.CN[name] && this.state.CN[name]['message'] ? this.state.CN[name]['message'] : '') : (this.state.CN[name] && this.state.EN[name]['message'] ? this.state.EN[name]['message'] : '')
	}

	initTempletTreeData(defaultFlag) { // 传入选择的科室ID
		let { currentLocData, userData } = this.state;
		var params = {
			params: [{
				admID: this.state.recordData ? (this.state.recordData.patAdmID || this.state.recordData.admID) : '',
				locID: currentLocData?.locID || userData?.locID || '',
				findDesc: this.state.templateDesc,
			}]
		}
		$http.post('urlDeault', this, {
			code: "03050036",
			data: params,
			success: function (res) {
				if (res.errorCode == '0') {
					var data = res.result;
					if (defaultFlag === 'Y') {
						var radioValue = ''
						if (!Util.isEmpty(data)) {
							for (var i = 0; i < data.length; i++) {
								if (data[i].default == 'Y') {
									radioValue = data[i].id
								}
							}
						}
						this.setState({ radioValue })
					}
					this.setState({
						templetTreeData: res.result,
						userLoginLoc: res?.userLoginLoc || [],
						nodeId: [],
					}, () => {
						this.loadEventKye()
					})
				}
			}
		});
	}

	// render: (text, data, index) => {
	//     return (!(Util.isEmpty(data.id))) || (!data.editable) ? <span>{data.diagDesc}</span> :
	//         <Select style={{ width: '98%' }}
	//             showSearch
	//             allowClear
	//             defaultActiveFirstOption={false}
	//             showArrow={false}
	//             filterOption={false}
	//             value={data.diagDesc ? data.diagDesc : this.state.changeValue}
	//             notFoundContent={null}
	//             onSearch={this.handleSearch.bind(this, index, data)}
	//             onDropdownVisibleChange={this.handleFocusInput.bind(this, index)}
	//             dropdownRender={(menuNode, props) => {
	//                 return (
	//                     <div
	//                         onMouseLeave={() => {
	//                             this.setState({
	//                                 visStatus: false,
	//                             })
	//                         }}
	//                         onMouseEnter={() => { this.setState({ visStatus: true }) }}
	//                     >
	//                         <Table
	//                             dataSource={this.state.selectData}
	//                             rowKey={(record) => record.id}
	//                             columns={data.diagCMarkID == "Z" ? this.SyndromeTypeColumns : this.dialogColumns}
	//                             bordered
	//                             pagination={false}
	//                             rowClassName={(data, index) => {
	//                                 return index == this.state.newIndex ? 'rowClass' : ''
	//                             }}
	//                             onRow={(record) => ({ onDoubleClick: (e) => { this.rowClick(record, index, e) } })}
	//                         />
	//                         <Pagination
	//                             size="small"
	//                             showQuickJumper
	//                             showSizeChanger
	//                             defaultCurrent={1}
	//                             current={this.state.page}
	//                             total={this.state.total}
	//                             onShowSizeChange={this.changePageSize.bind(this)}
	//                             onChange={this.onChange.bind(this)}
	//                             style={{ textAlign: "right", marginTop: '13px' }}
	//                         />
	//                     </div>
	//                 );
	//             }}
	//             dropdownMatchSelectWidth={false}
	//             dropdownStyle={{ width: '500px', height: 300, overflow: 'auto' }}
	//             open={(index == this.state.indexTable && (this.state.visible || this.state.visStatus)) ? true : false}></Select>
	// }

	initData() {
		this.columns = [
			{
				title: '类别',
				dataIndex: 'mark',
				width: '6.2%',
				align: 'center',
				render: (text, data, index) => {
					return (Util.isEmpty(data.id) && (data.editable)) ?
						<Select
							style={{ width: '98%', }} value={data.diagCMarkID || this.state.CMark}
							onChange={this.onCMarkChange.bind(this, index)}
						>
							{
								this.state.diagCategory && this.state.diagCategory.map((item) => {
									return (<Option key={item.code + ""} value={item.code}>{item.descripts}</Option>)
								})
							}
						</Select> : data.diagCMark
				}
			},
			{
				title: '诊断类型',
				dataIndex: 'diagType',
				width: '8.5%',
				align: 'center',
				render: (text, data, index) => {
					return ((Util.isEmpty(data.id)) || (data.editable)) && (data.diagCMarkID != "Z") ? <Select style={{ width: '98%' }} value={data.diagTypeID || this.state.diagTypeDefID} onChange={this.onDiagTypeChange.bind(this, index)} >
						{
							this.state.typeData && this.state.typeData.map((item) => {
								return (<Option key={item.id} value={item.id}>{item.descripts}</Option>)
							})
						}</Select> : data.diagTypeDesc
				}
			},
			//  {
			//     title: '级别',
			//     dataIndex: 'cat',
			//     width: 110,
			//     align: 'center',
			//     render: (text, data, index) => {
			//         return ((Util.isEmpty(data.id)) || (data.editable)) && (data.diagCMarkID != "Z") ? <Select style={{ width: '100%' }} value={data.catID || this.state.diagCatDefID} onChange={this.onCatChange.bind(this, index)} >{
			//             this.state.catData && this.state.catData.map((item) => {
			//                 return (<Option key={item.id} value={item.id}>{item.descripts}</Option>)
			//             })
			//         }</Select> : data.catDeschandleFocusInput
			//     }
			// },
			// {
			//     title: '诊断代码',
			//     dataIndex: 'diagCode',
			//     width: '9%',
			//     align: 'center',
			// },
			{
				title: '诊断名称',
				dataIndex: 'diagDesc',
				align: 'center',
				width: '22%',
				render: (text, data, index) => {
					return data.id ? <div style={{ textAlign: 'left', width: "100%" }}>{data.diagDesc}</div> :
						<Input style={{ width: '99%' }}
							id={"diagDesc-input" + index}
							onKeyDown={this.showCommonTableModal.bind(this, index, data, "diagDesc")} allowClear={true}
							autoFocus
							value={data.diagDesc || ''}
							onChange={this.handleSearchInput.bind(this, 'diagDesc', index, data)}
						/>
				}

			},
			//  {
			//     title: 'ICD代码',
			//     dataIndex: 'ICDCode',
			//     width: '7%',
			//     align: 'left',
			// },
			{
				title: 'ICD描述',
				dataIndex: 'ICDDesc',
				width: '22%',
				align: 'center',
				render: (text, data, index) => {
					return (data.id) || (data.diagCMarkID == "Z") ? <div style={{ textAlign: 'left', width: "100%" }}>{data.ICDDesc}</div> :
						<Input style={{ width: '99%' }} id={"ICDDesc-input" + index}
							onKeyDown={this.showCommonTableModal.bind(this, index, data, "ICDDesc")} allowClear={true}
							value={data.ICDDesc || ''}
							onChange={this.handleSearchInput.bind(this, 'ICDDesc', index, data)}
						/>
				}

			}, {
				title: '主诊断',
				dataIndex: 'mainDiag',
				width: '5.5%',
				align: 'center',
				render: (text, data, index) => {
					return <Checkbox onChange={this.onMainDiagChange.bind(this, index)} checked={data.mainDiagID == "Y"}
						disabled={((!data.editable) || (data.mainFlag != "Y"))}>
					</Checkbox>
				}
			}, {
				title: '诊断注释',
				dataIndex: 'descripts',
				align: 'center',
				render: (text, data, index) => {
					return (data.editable || (data.editable)) && (data.diagCMarkID != "Z") ? <Input key="descripts" style={{ width: '98%' }} onPressEnter={this.onDescriptsEnter} value={data.descripts} onChange={this.onDescChange.bind(this, index)} /> :
						<div style={{ textAlign: 'left', width: "100%" }}>{data.descripts}</div>
				}
			}, {
				title: '诊断状态',
				dataIndex: 'status',
				width: '6.5%',
				align: 'center',
				render: (text, data, index) => {
					return ((Util.isEmpty(data.id)) || (data.editable)) && (data.diagCMarkID != "Z") ? <Select style={{ width: '98%' }} value={data.diagStatusID || this.state.diagStatusDefID} onChange={this.onStatusChange.bind(this, index)}>{
						this.state.statusData && this.state.statusData.map((item) => {
							return (<Option key={item.id} value={item.id}>{item.descripts}</Option>)
						})
					}</Select> : data.diagStatusDesc
				}
			},
			{
				title: '发病日期',
				dataIndex: 'onsetDate',
				align: 'center',
				width: '11%',
				render: (text, data, index) => {
					return ((Util.isEmpty(data.id)) || (data.editable)) && (data.diagCMarkID != "Z") ? <DatePicker
						onChange={this.onsetDateChange.bind(this, index)}
						value={data.onsetDate ? moment(data.onsetDate, 'YYYY-MM-DD') : moment(new Date(), 'YYYY-MM-DD')}
						disabledDate={(curDate) => {
							return curDate && curDate > moment().endOf('day');
						}}
					>
					</DatePicker> : data.onsetDate
				}
			}
		]
		this.dialogColumns = [
			{
				title: '诊断编码',
				dataIndex: 'diagCode',
				width: 80,
				align: 'left',
			}, {
				title: '名称',
				dataIndex: 'diagDesc',
				width: 200,
				align: 'left',
			}, {
				title: 'ICD编码',
				dataIndex: 'ICDCode',
				width: 80,
				align: 'left',
			}, {
				title: 'ICD名称',
				dataIndex: 'ICDDesc',
				width: 200,
				align: 'left',
			}, {
				title: '版本号',
				dataIndex: 'ICDVersion',
				width: 60,
				align: 'left',
			}, {
				title: '医保诊断',
				dataIndex: 'insuFlag',
				width: 180,
				align: 'center',
			}, {
				title: '病种',
				dataIndex: 'diseaseDesc',
				width: 180,
				align: 'center',
			}
		]


		this.ICDColumns = [
			{
				title: 'ICD编码',
				dataIndex: 'ICDCode',
				width: 100,
				align: 'left',
			}, {
				title: 'ICD名称',
				dataIndex: 'ICDDesc',
				width: 220,
				align: 'left',
			}, {
				title: '版本号',
				dataIndex: 'ICDVersion',
				width: 80,
				align: 'left',
			}, , {
				title: '医保诊断',
				dataIndex: 'insuFlag',
				width: 180,
				align: 'center',
			}, {
				title: '病种',
				dataIndex: 'diseaseDesc',
				width: 180,
				align: 'center',
			}
		]
		this.SyndromeTypeColumns = [
			{
				title: '证型代码',
				dataIndex: 'code',
				width: 80,
				align: 'center',
			}, {
				title: '证型',
				dataIndex: 'desc',
				width: 180,
				align: 'center',
			}, {
				title: '医保诊断',
				dataIndex: 'insuFlag',
				width: 180,
				align: 'center',
			}, {
				title: '病种',
				dataIndex: 'diseaseDesc',
				width: 180,
				align: 'center',
			}
		]
	}

	//诊断注释回车事件
	onDescriptsEnter = () => {
		this.addDiag("1");
	}

	//诊断类别改变
	onCMarkChange = (index, value) => {
		let dataSource = this.state.dataSource;
		if (value == "Z") {
			if (dataSource.length < 2) {
				message.warn("请先添中医诊断", this.state.userData && this.state.userData.messageTime);
				return;
			} else {
				if ((dataSource[dataSource.length - 2].diagCMarkID != "Y") && (dataSource[dataSource.length - 2].diagCMarkID != "Z")) {
					message.warn("请先添中医诊断", this.state.userData && this.state.userData.messageTime);
					return;
				}
			}
		}

		this.setState({
			CMark: value,
		})
		dataSource[index].diagCMarkID = value;
		dataSource[index].diagCode = "";
		dataSource[index].diagDesc = "";
		dataSource[index].diagID = "";
		dataSource[index].mainFlag = undefined;
		dataSource[index]['ICDID'] = "";
		dataSource[index]['ICDDesc'] = "";
		dataSource[index]['ICDCode'] = "";

		let diagCMark = "中医";
		switch (value) {
			case "N":
				diagCMark = "西医";
				break;
			case "Y":
				diagCMark = "中医";
				break;
			case "Z":
				diagCMark = "证型";
				break;
		}
		dataSource[index]['diagCMark'] = diagCMark;
		this.forceUpdate();
	}

	//诊断类型改变
	onDiagTypeChange = (index, value, option) => {
		let dataSource = this.state.dataSource;
		dataSource[index].diagTypeID = value;
		dataSource[index].diagTypeCode = option.props.code;
		this.setState({ diagTypeDefID: value })
		if (!dataSource[index].id) { // 判断该条诊断是否已经保存过
			let isExistence = false;
			for (var i = 0; i < dataSource.length; i++) {
				if (dataSource[i].id && (dataSource[i].diagTypeID === value)) {
					isExistence = true;
					break;
				}
			}
			if (!isExistence) {
				dataSource[index].mainDiagID = "Y"; // 默认主诊断
			} else {
				dataSource[index].mainDiagID = "N"; // 默认主诊断
			}
		}
		this.forceUpdate();
	}

	//病情改变
	onConditionChange = (index, value) => {
		let dataSource = this.state.dataSource;
		dataSource[index].conditionID = value;
		this.forceUpdate();
	}

	//眼别
	onEyePartChange = (index, value) => {
		let dataSource = this.state.dataSource;
		dataSource[index].eyePartID = value;
		this.forceUpdate();
	}

	//公共下拉
	onChangeCommonSelect(name, index, e) {
		this.state.dataSource[index][name] = e
		this.setState({})
		this.forceUpdate();
	}

	//病种
	onDiseaseChange = (index, value) => {
		let dataSource = this.state.dataSource;
		dataSource[index].diseasesID = value;
		this.setState({ diseasesID: value })
		this.forceUpdate();
	}

	//诊断级别改变
	onCatChange = (index, value) => {
		let dataSource = this.state.dataSource;
		dataSource[index].catID = value;
		this.forceUpdate();
	}

	//是否主诊断
	onMainDiagChange = (data, index, e) => {
		let dataSource = this.state.dataSource;
		let value = "N";
		if (e.target.checked) {
			value = "Y";
		}

		if ((Util.isEmpty(dataSource[index].diagID)) && (Util.isEmpty(dataSource[index].ICDID))) {
			message.warn("请先添加诊断信息!", this.state.userData && this.state.userData.messageTime);
			return;
		}

		if ((dataSource[index].mainFlag !== "Y") && (value === "Y")) {
			message.warn("该诊断不能做为主诊断", this.state.userData && this.state.userData.messageTime);
			return;
		}

		// //只允许开一个主诊断
		// if (this.state.mainDiagFlag == 'Y') {
		//     for (var i = 0; i < dataSource.length; i++) {
		//         if (!Util.isEmpty(dataSource[i].id) && dataSource[i].mainDiagID == 'Y' && this.state.mainDiagExist) {
		//             message.error('已存在主诊断')
		//             return
		//         }
		//         if (value == 'Y' && i !== index) {
		//             dataSource[i].mainDiagID = 'N';
		//         }
		//     }
		// }
		for (var i = 0; i < dataSource.length; i++) {
			if (value == 'Y') {
				if (dataSource[i].diagTypeID == data.diagTypeID && dataSource[i].mainDiagID == 'Y') {
					message.error('该诊断类型已存在一个主诊断！')
					return
				}
			} else {
				if (dataSource[i].diagTypeID == data.diagTypeID && dataSource[index].mainDiagID == 'N') {
					dataSource[index].mainDiagID = value;
				}
			}
		}

		dataSource[index].mainDiagID = value;
		this.forceUpdate();
	}

	//诊断状态
	onStatusChange = (index, value) => {
		let dataSource = this.state.dataSource;
		dataSource[index].diagStatusID = value;
		this.forceUpdate();
	}

	//诊断注释
	onDescChange = (index, e) => {
		let dataSource = this.state.dataSource;
		dataSource[index].descripts = e.target.value;
		this.forceUpdate();
	}

	//onfocus名称规格展示下拉table
	handleFocusInput(index, e) {
		this.setState({
			indexTable: index,
			visible: e,
		})
	}

	onsetDateChange = (index, date, dateString) => {
		let dataSource = this.state.dataSource;
		dataSource[index].onsetDate = dateString;
		this.forceUpdate();
	}

	//分页切换
	changePageSize(current, pageSize) {
		if ((pageSize == this.state.pageSize) && (current == this.state.page)) {
			if (this.state.rowMedID) {
				let oneArr = this.state.selectData && this.state.selectData.length > 0 ? this.state.selectData : [];
				let obj = {}
				for (var i = 0; i < oneArr.length; i++) {
					if (oneArr[i].id === this.state.rowMedID) {
						obj = i > 0 ? oneArr[i] : oneArr[0];
						break;
					}
				}
				if (this.state.changename == "ICDDesc") {
					this.ICDRowClick(obj)
				} else {

					this.rowClick(obj)
				}
			}
		} else {
			this.setState({ pageSize: pageSize, page: current }, () => {
				this.loadSelectData('', current, pageSize);
			});
		}
	}

	//分页切换
	onChange = (page, pageSize) => {
		this.setState({ page: page }, () => {
			this.loadSelectData('', page, '');
		});
	}

	///ICD 诊断下拉选中事件
	ICDRowClick = (record, index, e) => {
		index = this.state.selectIndex;

		if (e) { e.stopPropagation(); }
		let dataSource = this.state.dataSource;
		dataSource[index]['ICDID'] = record['ICDID'] || record['id']
		dataSource[index]['ICDDesc'] = record['ICDDesc'] || record['desc'];
		dataSource[index]['ICDCode'] = record['ICDCode'] || record['code'];
		//添加医保
		dataSource[index]['insuDesc'] = record['insuDesc'] || '';
		dataSource[index]['insuCode'] = record['insuCode'] || '';
		/**
		 * 针对国际医疗修改
		 */
		///---------------------------------------
		dataSource[index]['mainFlag'] = "Y";
		let diagCMark = "中医";
		switch (record['CMark']) {
			case "N":
				diagCMark = "西医";
				break;
			case "Y":
				diagCMark = "中医";
				break;
			case "Z":
				diagCMark = "证型";
				break;
		}
		dataSource[index]['diagCMark'] = diagCMark;
		let CMark = this.state.CMark;
		if (record['CMark'] == "Y") {
			CMark = "Z";
		}
		///----------------国际医疗中心添加-----------------------
		this.setState({
			visible: false,
			selectData: [],
			total: 0,
			page: 1,
			dataSource: dataSource,
			visStatus: false,
			CMark: CMark, //国际医疗中心添加
			indexTab: '-1',
		}, () => {
			///---------------国际医疗中心添加------------------------
			this.addDiag("1");
			///---------------------------------------
			this.child.handleCancel();
			if (!Util.isEmpty(record.diseaseID)) {
				let ICDArr = []
				ICDArr.push(record['ICDID'])
				this.ifExistInfectiousReport(ICDArr, record.diseaseID);
			}
		})
	}

	///诊断下拉框双击
	rowClick = (record, index, e) => {
		index = this.state.selectIndex;
		if (e) { e.stopPropagation(); }
		let dataSource = this.state.dataSource;
		let findFlag = false;
		for (var i = 0; i < dataSource.length; i++) {
			let obj = dataSource[i];
			if ((obj.diagID == record['id']) && (i !== index) && (this.state.searchData.diagCMarkID != "Z") && dataSource[i].diagTypeID == dataSource[index].diagTypeID) {
				findFlag = true;
			}
		}
		if (findFlag) {
			message.error("已存在该诊断!", this.state.userData && this.state.userData.messageTime);
			return;
		}
		dataSource[index]['diagCode'] = record['diagCode'] || record['code'];
		dataSource[index]['diagDesc'] = record['diagDesc'] || record['desc'];
		dataSource[index]['insuFlag'] = record['insuFlag'];
		dataSource[index]['diseasesID'] = record['diseasesID'];
		dataSource[index]['diagID'] = record['id'];
		dataSource[index]['ICDID'] = record['ICDID'];
		dataSource[index]['ICDDesc'] = record['ICDDesc'];
		dataSource[index]['ICDCode'] = record['ICDCode'];
		//医保
		dataSource[index]['insuDesc'] = record['insuDesc'];
		dataSource[index]['insuCode'] = record['insuCode'];
		dataSource[index]['mainFlag'] = record['mainFlag']; //是否可作为主诊断
		if (dataSource.length == 1 && record['mainFlag'] == "Y") {
			dataSource[index].mainDiagID = "Y"
		}
		let diagCMark = "中医";
		switch (record['CMark']) {
			case "N":
				diagCMark = "西医";
				break;
			case "Y":
				diagCMark = "中医";
				break;
			case "Z":
				diagCMark = "证型";
				break;
		}
		dataSource[index]['diagCMark'] = diagCMark;
		let CMark = this.state.CMark;
		if (record['CMark'] == "Y") {
			CMark = "Z";
		}
		scrollCount = 0
		this.setState({
			visible: false,
			selectData: [],
			total: 0,
			page: 1,
			dataSource: dataSource,
			visStatus: false,
			CMark: CMark,
			indexTab: '-1',
		}, () => {
			this.addDiag("1");
			this.child.handleCancel();
			if (!Util.isEmpty(record.diseaseID)) {
				let ICDArr = []
				ICDArr.push(record['ICDID'])
				this.ifExistInfectiousReport(ICDArr, record.diseaseID);
			}
		})
	}

	//诊断记录双击
	onDiagRowClick = (record, index, e) => {
		let dataSource = this.state.dataSource;
		dataSource[index].editable = true;
		dataSource[index].diagTypeID = dataSource[index].diagTypeID + "";
		let editData = this.state.editData;
		editData.push(index);
		this.setState({
			dataSource: dataSource,
			editData: editData,
		});
	}

	loadSelectData(value, page, pageSize) {
		this.setState({ loading: true });
		var params = {
			params: [{
				desc: value || this.state.changeValue,
				hospID: this.state.userData.hospID,
				CMark: this.state.searchData.diagCMarkID,
				admID: this.state.recordData.patAdmID || this.state.recordData.admID,
				diseasesID: this.state.diseasesID,
				eyesDiagnosis: (this.state.changename == 'ICDDesc') && (this.state.searchData.diagCMarkID != "Z") ? undefined : (this.state.checked == true ? 'Y' : 'N')
			}],
			pagination: [{
				pageSize: this.state.pageSize,
				currentPage: page
			}]

		}
		let serverCode = "03050031"
		if ((this.state.changename == 'ICDDesc') && (this.state.searchData.diagCMarkID != "Z")) {
			serverCode = "03050094";
		}
		$http.post('urlDeault', this, {
			code: serverCode,
			data: params,
			success: function (res) {
				if (res.errorCode == '0') {
					let rowMedID = "";
					if ((res.result.data) && (res.result.data.length > 0)) {
						rowMedID = res.result.data[0].id
					}
					this.setState({
						selectData: res.result.data,
						total: res.result.totalCount,
						rowMedID: rowMedID,
						loading: false,
					})
				} else {
					this.setState({ loading: false });
				}
			},
			error: function () {
				this.setState({ loading: false });
			}
		});
	}

	loadData() {
		//加载类型，状态等基础数据
		this.loadBaseData();
	}

	loadBaseData() {
		let admID = recordData ? recordData.admID : ''
		var params = {
			params: [{
				admID: recordData ? recordData.admID : '',
			}]
		}
		$http.post('urlDeault', this, {
			code: "03050030",
			data: params,
			success: function (res) {
				if (res.errorCode == '0') {
					this.setState({
						typeData: res.result.diagType, //诊断类型
						statusData: res.result.diagStatus,//诊断备注
						catData: res.result.diagCat, //诊断级别
						medicalType: res.result.medicalType, //复诊类型
						templetType: res.result.templetType, //模板类型
						diagTypeDefID: res.result.diagTypeDefID,//诊断类型默认ID
						diagCatDefID: res.result.diagCatDefID,  //诊断级别默认ID
						diagStatusDefID: res.result.diagStatusDefID, //诊断备注默认ID
						admInfo: res.result.admInfo,
						diagCategory: res.result.diagCategory,   //诊断类别
						selectedMode: res.result.selectedMode,
						conditionData: res.result.conditionData, //病情
						conditionDefID: res.result.conditionDefID,  // 默认病情
						eyePart: res.result.eyePart,  // 眼别
						disease: res.result.diseases,  // 病种
						disCondition: res.result.disCondition ? res.result.disCondition.result : [],  // 出院情况
					}, () => {
						//加载完基础信息后再去加载患者诊断及历史诊断，防止诊断类型等数据不能赋值问题
						this.loadPatDiagData("Y");
					})
				}
			}
		});
	}

	//加载本次诊断及历史诊断
	loadPatDiagData(historyFlag) {
		var params = {
			params: [{
				admID: this.state.recordData ? (this.state.recordData.patAdmID || this.state.recordData.admID) : '',
				patID: this.state.recordData ? this.state.recordData.patID : '',
				historyFlag: historyFlag,
				historyType: this.state.admType,
				syFlag: "Y",
			}]
		}
		$http.post('urlDeault', this, {
			code: "03050033",
			data: params,
			success: function (res) {
				if (res.errorCode == '0') {
					this.setState({
						dataSource: res.result.diagList, //本次诊断
						historyDiag: res.result.historyDiagList, //历史诊断
						patHeight: res.result.medRecord.height,
						patWeight: res.result.medRecord.weight,
						diastolic: res.result.medRecord.diastolic,
						systolic: res.result.medRecord.systolic,
						temperature: res.result.medRecord.temperature,
						pulse: res.result.medRecord.pulse,
						breath: res.result.medRecord.breath,
						mainDiagExist: res.result.mainDiagExist,
						mainDiagFlag: res.result.mainDiagFlag,
						medicalTypeID: res.result.medRecord.medTypeID,
						admType: this.state.admType == "" ? res.result.historyType : this.state.admType,
						editData: [],
					}, () => {
						this.addDiag("1");
					})
				}
			}
		});
	}

	//加载历史诊断
	loadHistoryDiagData(admType) {
		var params = {
			params: [{
				admID: this.state.recordData.patAdmID || this.state.recordData.admID,
				patID: this.state.recordData.patID,
				historyType: admType,
				historyFlag: "Y",
			}]
		}
		$http.post('urlDeault', this, {
			code: "03050033",
			data: params,
			success: function (res) {
				if (res.errorCode == '0') {
					this.setState({
						historyDiag: res.result.historyDiagList, //历史诊断
						mainDiagExist: res.result.mainDiagExist,
						mainDiagFlag: res.result.mainDiagFlag,
						admType: admType,
					})
				}
			}
		});
	}

	onSelectChange(ids) {
		this.setState({
			ids
		})
	}

	//添加空白诊断
	addDiag(flag, e) {
		var { dataSource } = this.state;
		//加入添加限制，只有录入了医嘱信息之后才能再次添加
		for (var i = 0; i < dataSource.length; i++) {
			if ((Util.isEmpty(dataSource[i].diagID)) && (Util.isEmpty(dataSource[i].id)) && (Util.isEmpty(dataSource[i].descripts)) && (Util.isEmpty(dataSource[i].ICDID))) {
				if (flag === "0") message.error('请先录入诊断信息再添加！', this.state.userData && this.state.userData.messageTime);
				return
			}
		}
		let editData = this.state.editData;
		editData.push(this.state.dataSource.length);
		let lastCMark = this.state.CMark;
		if (dataSource.length > 0) {
			if (dataSource[dataSource.length - 1].diagCMarkID != "N") {
				lastCMark = "Z";
			} else {
				if (lastCMark == "Z") {
					lastCMark = "N";
				}
			}
		} else {
			if (lastCMark == "Z") {
				lastCMark = "N";
			}
		}

		let data = {
			diagCMarkID: lastCMark,
			mainDiagID: this.state.mainDiag,
			diagTypeID: this.state.diagTypeDefID,
			catID: this.state.diagCatDefID,
			diagStatusID: this.state.diagStatusDefID,
			index: this.state.dataSource.length + 1,
			editable: true,
		}
		dataSource.push(data);
		this.setState({ indexTable: dataSource.length - 1, selectIndex: this.state.dataSource.length + 1, visStatus: true, CMark: lastCMark, editData: editData, dataSource: dataSource })
	}

	//提示框点击取消
	onMsgCancel = () => {
		this.setState({
			msgVisible: false,
		})
	}

	//提示框点击确认
	onMsgOk = () => {
		const ids = this.state.ids;
		let oldDataSource = [].concat(this.state.dataSource);
		let dataSource = this.state.dataSource;
		let delSavedRecord = [];  //已保存记录
		let newIds = [];
		let editData = [];
		let newRowDel = false; //新添加的行是否被删除
		//先清空编辑, 删除后的数据都置为 编辑状态
		for (var i = 0; i < ids.length; i++) {
			//未保存的诊断
			let id = ids[i] - 1;
			let diag = oldDataSource[id];
			if (!Util.isEmpty(diag.id)) {
				delSavedRecord.push(diag);
			}
			if ((Util.isEmpty(diag.diagDesc)) && (Util.isEmpty(diag.descripts))) {
				newRowDel = true;
			}
			for (var j = 0; j < dataSource.length; j++) {
				if ((dataSource[j].index + "") === (ids[i] + "")) {
					dataSource.splice(j, 1);
				}
			}
		}
		for (var j = 0; j < dataSource.length; j++) {
			editData.push(j);
		}
		//删除后重新排序
		dataSource = this.sortDataSource(dataSource);
		let lastCMark = this.state.CMark;
		if (!newRowDel) {
			if (dataSource.length > 2) {
				if ((dataSource[dataSource.length - 2].diagCMarkID == "N") && (dataSource[dataSource.length - 1].diagCMarkID == "Z")) {
					dataSource[dataSource.length - 1].diagCMarkID = "N";
					lastCMark = "N";
				}
			} else {
				if (dataSource.length != 0) {
					dataSource[dataSource.length - 1].diagCMarkID = "N";
					lastCMark = "N";
				}
			}
		}

		if (delSavedRecord.length !== 0) {
			var params = {
				params: [{
					userID: this.state.userData.userID,
					delData: delSavedRecord,
				}]
			}
			$http.post('urlDeault', this, {
				code: "03050037",
				data: params,
				success: function (res) {
					if (res.errorCode == '0') {
						this.setState({
							msgVisible: true,
							msg: "删除成功",
							msgDelayed: true,
							CMark: lastCMark,
							ids: newIds,
							msgFooter: false,
							dataSource: dataSource,
							editData: editData,
						}, () => {
							if ((newRowDel) || (dataSource.length === 0)) {
								this.addDiag("1");
							}
						})
					}
				}
			});
		} else {
			this.setState({
				msgVisible: true,
				msg: "删除成功",
				msgDelayed: true,
				ids: newIds,
				msgFooter: false,
				dataSource: dataSource,
				CMark: lastCMark,
				editData: editData,
			}, () => {
				if ((newRowDel) || (dataSource.length === 0)) {
					this.addDiag("1");
				}
			})
		}
	}

	sortDataSource = (dataSource) => {
		let newDataSource = [];
		dataSource.map((item, index) => {
			let obj = item;
			obj.index = index + 1;
			newDataSource.push(obj);
		});
		return newDataSource;
	}

	//上移
	handleUpSort(e) {
		var ids = this.state.ids;
		let data = this.state.dataSource;
		var flage = false
		for (var i = 0; i < ids.length; i++) {
			var id = ids[i] - 1
			if (data[id].id != "" && data[id].id != undefined) {
				flage = true
			}
		}
		if (flage) {
			// message.warn("不能移动已保存的诊断", this.state.userData && this.state.userData.messageTime)
		}
		var YZindex = []   //中医类中证型的下标
		if (this.state.ids.length === 0) {
			message.warn("请选择要移动的行", this.state.userData && this.state.userData.messageTime);
			return;
		}
		if (!this.DecideZInY()) {
			message.warn("移动证型必须要选择所有的证型和它的中医", this.state.userData && this.state.userData.messageTime);
			return;
		}

		for (var i = 0; i < ids.length; i++) {
			let id = ids[i] - 1;
			if (data[id].diagCMarkID == "Y") {
				for (var j = 1; j < data.length - id; j++) {
					if (data[id + j].diagCMarkID == "Z") {
						//如果诊断名称为空则不存储
						if (!Util.isEmpty(data[id + j].diagDesc)) {
							YZindex[j - 1] = id + j + 1;
						}
					} else {
						break;
					}
				}
			}
		}
		ids = this.unique5(ids);
		//判断是否包含中医下所有的证型
		var containsFlage = 0;
		for (var i = 0; i < ids.length; i++) {
			for (var j = 0; j < YZindex.length; j++) {
				if (ids[i] == YZindex[j]) {
					containsFlage = containsFlage + 1;
				}
			}
		}
		if (containsFlage != YZindex.length) {
			message.warn("请选择中医下的所有证型", this.state.userData && this.state.userData.messageTime);
			return;
		}

		ids = ids.sort(function (m, n) {
			if (m < n) return -1
			else if (m > n) return 1
			else return 0
		});

		if (data[data.length - 1].editable) {
			data.splice(data.length - 1, 1)
		}

		//移动选中的上移
		var newKeys = [];
		var temp = [];
		for (var i = 0; i < data.length; i++) {
			if (!Util.isEmpty(data[i].catID)) {
				temp.push(data[i])
			}
		}

		ids = ids.sort(function (m, n) {
			if (m < n) return -1
			else if (m > n) return 1
			else return 0
		});
		if (ids[0] == 1) {
			message.warn("已经到顶了", this.state.userData && this.state.userData.messageTime);
			this.setState(
				{
					dataSource: data,
					ids: ids
				}
			)
			this.addDiag("1");
			return;
		}
		for (var i = 0; i < ids.length; i++) {
			var n = 0;
			if (data[ids[i] - 1].diagCMarkID != null) {
				for (var j = 1; j < ids[i]; j++) {
					if (data[ids[i] - 1 - j].diagCMarkID == "Z") {
						n++;
					} else if (data[ids[i] - 1 - j].diagCMarkID == "Y") {
						break;
					} else {
						break;
					}
				}
			}
			if (n > 0) {
				for (var j = 0; j <= n; j++) {
					var curRowData = data[ids[i] - 1 - j]
					var curRowKey = curRowData.index
					var upRowData = data[ids[i] - 2 - j]
					var upRowKey = upRowData.index
					upRowData.index = curRowKey
					curRowData.index = upRowKey
					data[ids[i] - 1 - j] = upRowData
					data[ids[i] - 2 - j] = curRowData
					if (newKeys.length > 0) {
						if (newKeys.indexOf(ids[i] - 1 - n) == -1) {
							newKeys.push(ids[i] - 1 - n)
						}
					} else {
						newKeys.push(ids[i] - 1 - n)
					}

					if (Util.isEmpty(data[ids[i] - 2 - j].index)) {
						return
					}
				}
			} else {
				var curRowData = data[ids[i] - 1]
				var curRowKey = curRowData.index
				var upRowData = data[ids[i] - 2]
				var upRowKey = upRowData.index
				upRowData.index = curRowKey
				curRowData.index = upRowKey;
				data[ids[i] - 1] = upRowData
				data[ids[i] - 2] = curRowData
				if (newKeys.length > 0) {
					if (newKeys.indexOf(ids[i] - 1) == -1) {
						newKeys.push(ids[i] - 1)
					}
				} else {
					newKeys.push(ids[i] - 1)
				}

				if (Util.isEmpty(data[ids[i] - 2].index)) {
					return
				}
			}

		}
		let editData = [];
		data.map((item, index) => {
			editData.push(index);
		})
		this.setState(
			{
				dataSource: data,
				ids: newKeys,
				editData: editData,
			}, () => {
				this.addDiag("1")
			}
		)

	}

	handleDownSort(e) {
		var ids = this.state.ids;
		var data = this.state.dataSource
		var YZindex = []   //中医类中证型的下标
		var flage = false
		for (var i = 0; i < ids.length; i++) {
			var id = ids[i] - 1
			if (data[id].id != "" && data[id].id != undefined) {
				flage = true
			}
		}
		if (flage) {
			//message.warn("不能移动已保存的诊断", this.state.userData && this.state.userData.messageTime)
		}

		if (this.state.ids.length === 0) {
			message.warn("请选择要移动的行", this.state.userData && this.state.userData.messageTime);
			return;
		}
		if (!this.DecideZInY()) {
			message.warn("移动证型必须要选择所有的证型和它的中医", this.state.userData && this.state.userData.messageTime);
			return;
		}
		let savedFlag = false;
		for (var i = 0; i < ids.length; i++) {
			let id = ids[i] - 1;
			if (!Util.isEmpty(data[id].id)) {
				savedFlag = true;
			}
			if (data[id].diagCMarkID == "Y") {
				for (var j = 1; j < data.length - id; j++) {
					if (data[id + j].diagCMarkID == "Z") {
						//如果诊断名称为空则不存储
						if (!Util.isEmpty(data[id + j].diagDesc)) {
							YZindex[j - 1] = id + j + 1;
						}
					} else {
						break;
					}
				}
			}
		}
		ids = this.unique5(ids);
		//判断是否包含中医下所有的证型
		var containsFlage = 0;
		for (var i = 0; i < ids.length; i++) {
			for (var j = 0; j < YZindex.length; j++) {
				if (ids[i] == YZindex[j]) {
					containsFlage = containsFlage + 1;
				}
			}
		}
		if (containsFlage != YZindex.length) {
			message.warn("请选择中医下的所有证型", this.state.userData && this.state.userData.messageTime);
			return;
		}
		ids = ids.sort(function (m, n) {
			if (m < n) return -1
			else if (m > n) return 1
			else return 0
		});

		if (data[data.length - 1].editable) {
			data.splice(data.length - 1, 1)
		}

		ids = ids.sort(function (m, n) {
			if (m < n) return -1
			else if (m > n) return 1
			else return 0
		});
		var newKeys = [];
		//要替换的下标
		var tempKeys = [].concat(ids);
		//上一次移动的次数
		var moveCount = 0;
		if (ids[ids.length - 1] == data.length) {
			message.warn("已经到底了", this.state.userData && this.state.userData.messageTime);
			this.setState(
				{
					dataSource: data,
					ids: ids
				}
			)
			this.addDiag("1");
			return;
		}
		for (var i = 0; i < ids.length; i++) {
			//n：判断要下移几行
			var n = 0;
			//YCount：是中医/西医出现的次数
			var YCount = 0;
			//当前后面还有多少个连续勾选的数据
			var serialCount = 0;
			if (!data[ids[i] - 1].editable) {
				//连续选中的数据  移动的行数都是一样的
				if (ids.indexOf(ids[i] - 1) != -1) {
					n = moveCount;
				} else {
					// 判断下一行是否是被选中的一行 如果是serialCount+1
					if (tempKeys.length > 1) {
						for (var p = 1; p < tempKeys.length; p++) {
							if (tempKeys.indexOf(tempKeys[i] + p) != -1) {
								serialCount = serialCount + 1;
							} else {
								break;
							}
						}
					}

					//判断下一行是什么  如果是N：西医 直接移动  如果是Y：中医说明下一行是Z：证型或者N：西医,n++
					for (var j = serialCount; j < data.length - tempKeys[i]; j++) {
						if (data[tempKeys[i] + j].diagCMarkID == "Y" && YCount == 0) {
							n++;
							YCount++;
							continue;
						} else if (data[tempKeys[i] + j].diagCMarkID == "Z") {
							n++;
							continue;
						} else if (data[tempKeys[i] + j].diagCMarkID == "N" && YCount == 0) {
							n++
							break;
						}
						break;
					}
					moveCount = n + serialCount;
				}
			}
			n = moveCount;
			if (n > 1) {
				//向下移动  n 为向下移动的行数
				for (var j = 0; j < n; j++) {
					var curRowData = data[tempKeys[i] - 1 + j]
					var curRowKey = curRowData.index
					var upRowData = data[tempKeys[i] + j]
					var upRowKey = upRowData.index
					upRowData.index = curRowKey
					curRowData.index = upRowKey
					data[tempKeys[i] - 1 + j] = upRowData
					data[tempKeys[i] + j] = curRowData
				}
				tempKeys[i] = tempKeys[i] + moveCount;
				//往下判断 是否被当前行移动影响到的数据下标-1
				for (var j = 1; j < tempKeys.length; j++) {
					if (ids.indexOf(ids[i] + j) != -1) {
						if (tempKeys[i + j] <= tempKeys[i]) {
							tempKeys[i + j]--;
						} else {
							break;
						}
					} else {
						break;
					}
				}
				//往上判断 是否被当前行移动影响到的数据下标-1
				for (var j = 1; j < i + 1; j++) {
					if (ids.indexOf(ids[i] - j) != -1) {
						if (tempKeys[i - j] <= tempKeys[i]) {
							tempKeys[i - j]--;
						} else {
							break;
						}
					} else {
						break;
					}
				}
			} else {
				var curRowData = data[ids[i] - 1]
				var upRowData = data[ids[i]]
				var curRowKey = curRowData.index
				var upRowKey = upRowData.index
				upRowData.index = curRowKey
				curRowData.index = upRowKey
				data[ids[i] - 1] = upRowData
				data[ids[i]] = curRowData
				tempKeys[i] = ids[i] + 1
			}

		}

		let editData = [];
		data.map((item, index) => {
			editData.push(index);
		})
		this.setState(
			{
				dataSource: data,
				ids: newKeys,
				editData: editData,
			}, () => {
				this.addDiag("1")
			}
		)

	}

	DecideZInY() {
		var Flag = true;
		var ids = this.state.ids;
		var data = this.state.dataSource;
		var Yindex = [];
		var Zindex = [];
		ids = ids.sort(function (m, n) {
			if (m < n) return -1
			else if (m > n) return 1
			else return 0
		});
		ids = this.unique5(ids);
		for (var i = 0; i < ids.length; i++) {
			if (data[ids[i] - 1].diagCMarkID == "Z") {
				Zindex.push(ids[i])
			}
		}
		var ZForIndex = 0;
		for (var j = Zindex[0] - 1; j < Zindex[Zindex.length - 1]; j++) {
			if (j != Zindex[ZForIndex]) {
				if (data[j - 1].diagCMarkID == "Y") {
					Yindex.push(j);
				}
			}
			if (j == Zindex[ZForIndex]) {
				ZForIndex++;
			}
		}

		var YCount = 0;
		for (var i = 0; i < ids.length; i++) {
			for (var j = 0; j < Yindex.length; j++) {
				if (ids[i] == Yindex[j]) {
					YCount++;
				}
			}
		}

		if (YCount != Yindex.length) {
			Flag = false;

		}

		return Flag;
	}

	//删除
	delDiag = (e) => {
		const ids = this.state.ids;
		if (this.state.ids.length === 0) {
			message.warn("请选择要删除的行", this.state.userData && this.state.userData.messageTime);
			return;
		}
		let findFlag = true;
		let savedFlag = false;
		let dataSource = this.state.dataSource;
		let error = "";
		let ICDIDArr = [];
		for (var i = 0; i < ids.length; i++) {
			let id = ids[i] - 1;
			if ((!Util.isEmpty(dataSource[id].diagDesc)) || (!Util.isEmpty(dataSource[id].descripts)) || (!Util.isEmpty(dataSource[id].ICDID))) {
				findFlag = false;
				if (!Util.isEmpty(dataSource[id].ICDID)) {
					ICDIDArr.push(dataSource[id].ICDID)
				}
			}
			if (!Util.isEmpty(dataSource[id].id)) {
				savedFlag = 1;
			}
			if (dataSource[id].diagCMarkID == "Y") {
				for (var j = id + 1; j < dataSource.length; j++) {
					if (dataSource[j].diagCMarkID == "Z") {
						if (("^" + ids.join("^") + "^").indexOf("^" + j + "^") < 0) {
							error = "删除中医诊断需同时删除诊断下的所有证型";
						}
					}
				}
			}
		}
		if (error != "") {
			this.setState({
				msgVisible: true,
				msgType: 'warn',
				msg: error,
				msgFooter: false,
				msgDelayed: true,
			})
			return;
		}
		if (findFlag) {
			this.setState({
				msgVisible: true,
				msgType: 'warn',
				msg: "没有要删除的数据",
				msgDelayed: true,
			})
			return;
		}
		let msg = "是否确认删除";
		if (ICDIDArr.length > 0) {
			let data = {
				params: [{
					admID: recordData.admID,
					ICDIDArr
				}]
			}
			$http.post('urlDeault', this, {
				code: "04190015",
				data: data,
				success: function (res) {
					if (res.errorCode == '0') {
						if (res.result == 1) {
							msg = "选中项中有传染病报告诊断,是否确认删除！！！";
							this.setState({
								msgVisible: true,
								msgOkText: "确认",
								msgCancelText: "取消",
								msg: msg,
								msgType: 'warn',
								msgFooter: true,
								msgDelayed: false,
								delSaved: false,
							})
						} else {
							if (savedFlag) {
								msg = "选中项中有已保存诊断,是否确认删除！！！";
							}
							this.setState({
								msgVisible: true,
								msgOkText: "确认",
								msgCancelText: "取消",
								msg: msg,
								msgType: 'warn',
								msgFooter: true,
								msgDelayed: false,
								delSaved: false,
							})
						}
					}
				}
			});
		} else {
			if (savedFlag) {
				msg = "选中项中有已保存诊断,是否确认删除！！！";
			}
			this.setState({
				msgVisible: true,
				msgOkText: "确认",
				msgCancelText: "取消",
				msg: msg,
				msgType: 'warn',
				msgFooter: true,
				msgDelayed: false,
				delSaved: false,
			})
		}
	}

	// 判断诊断是否有对应传染病报告
	ifExistInfectiousReport = (ICDIDArr, diseaseID) => {
		let data = {
			params: [{
				admID: recordData.admID,
				ICDIDArr
			}]
		}
		$http.post('urlDeault', this, {
			code: "04190015",
			data: data,
			success: function (res) {
				if (res.errorCode == '0') {
					if (res.result == 0) {
						if (!Util.isEmpty(diseaseID)) {
							this.setState({
								diseaseID: diseaseID
							}, () => this.childInfectious.showModal())
						}
					}
				}
			}
		});
	}

	//添加模版
	addTemplateModal() {
		this.setState({
			isAddTemplateModal: true
		})
	}

	onAddTemplateMOdal() {

	}

	/** 去重*/
	unique5(arr) {
		var x = new Set(arr);
		return [...x];
	}

	//点击保存，回传current，渲染步骤进度
	saveDiagnosisMsg = () => {
		// 判断是否有未测血压
		const { typeData, mainDiagConfig } = this.state;
		if (this.state.measureFlag == 'Y') {
			if (this.state.systolic == '' || this.state.diastolic == '' || this.state.systolic == undefined || this.state.diastolic == undefined) {
				message.warning(this.state.measureAge + this.display('DiagTableblood'));
				// this.myRef1.current.focus();
				return;
			}
		};
		let findFlag = false;
		let editData = this.state.editData;
		let dataSource = this.state.dataSource;
		// 不同类型诊断必须有一个主诊断
		let diagObj = {};
		for (let i = 0; i < dataSource.length; i++) {
			let diagTypeID = dataSource[i]?.diagTypeID || '';
			if (dataSource[i] && dataSource[i].diagID && diagTypeID) {
				let objKey = 'diagTypeID' + diagTypeID;
				if (!(diagObj && objKey in diagObj && diagObj[objKey])) {
					diagObj[objKey] = [dataSource[i]];
				} else {
					diagObj[objKey].push(dataSource[i]);
				}
			}
		}
		for (let diagKey in diagObj) {
			if (diagObj && diagObj[diagKey] && Array.isArray(diagObj[diagKey])) {
				let mainFlag = false;
				let currentDiagTypeID = diagObj[diagKey][0]?.diagTypeID || '';
				for (var i = 0; i < diagObj[diagKey].length; i++) {
					if (diagObj[diagKey][i].mainDiagID === 'Y') {
						mainFlag = true;
						break;
					}
				}
				if (!mainFlag) {
					let diagTypeDesc = Util.returnDataCccordingToAttributes(typeData, currentDiagTypeID)?.descripts || '';
					if (mainDiagConfig === 'Y') {
						message.error('【' + diagTypeDesc + '】没选主诊断，请勾选主诊断再保存！');
						return;
					} else {
						message.warning('【' + diagTypeDesc + '】没选主诊断，如需修改可删除后重新下！');
					}
				}
			}
		}
		for (var i = 0; i < editData.length; i++) {
			let diag = dataSource[editData[i]];
			if (!Util.isEmpty(diag)) {
				if (!(Util.isEmpty(diag.diagID)) || (!Util.isEmpty(diag.descripts)) || (!Util.isEmpty(diag.ICDID))) {
					findFlag = true;
				}
			}
		};
		let diagData = [];
		if (findFlag) {
			editData = this.state.dataSource;
			for (var i = 0; i < editData.length; i++) {
				if (editData[i].diagTypeCode == 'DIS' && (Util.isEmpty(editData[i].disConditionID) || Util.isEmpty(editData[i].conditionID))) {
					message.error('诊断类型为出院诊断时，出院情况、病情为必填，请重新选择！')
					return
				}
				let diagID = editData[i].diagID, descripts = editData[i].descripts, ICDID = editData[i].ICDID;
				if ((!Util.isEmpty(diagID)) || (!Util.isEmpty(descripts)) || (!Util.isEmpty(ICDID))) {
					diagData.push(editData[i]);
				}
			}
		};
		var params = {
			params: [{
				admID: this.state.recordData.patAdmID || this.state.recordData.admID,
				userID: this.state.userData.userID,
				locID: this.state.userData.locID,
				diagData: diagData,
				diastolic: this.state.diastolic,
				systolic: this.state.systolic,
				patHeight: this.state.patHeight,
				patWeight: this.state.patWeight,
				medicalTypeID: this.state.medicalTypeID,
				temperature: this.state.temperature,
				pulse: this.state.pulse,
				breath: this.state.breath,
			}]
		}
		$http.post('urlDeault', this, {
			code: "03050032",
			data: params,
			success: function (res) {
				if (res.errorCode == '0') {
					var { saveDiagnosisMsg } = this.props;
					this.setState({ dataSource: [], editData: [] }, () => {
						this.loadPatDiagData("Y");
					})
					message.success(res.errorMessage, this.state.userData && this.state.userData.messageTime);
					// if (saveDiagnosisMsg) {
					//     saveDiagnosisMsg(2)
					// }
				}
			}
		});
	}

	///就诊类型改变
	onAdmTypeChange = (e) => {
		this.loadHistoryDiagData(e.target.value);
	}

	///初复诊类型改变
	onMedicalTypeChange = (e) => {
		this.setState({
			medicalTypeID: e.target.value,
		})
	}

	///历史诊断科室点击
	onLocClick = () => {

	}
	//保存时校验血压等数据
	regexData = () => {
		//非负 浮点数校验
		let regex = /^\d+(\.\d+)?$/;
	}

	//其他信息改变时触发
	onOtherChange = (other, e) => {
		const value = e.target.value;
		if (!value) {
			this.setState({
				[other]: value,
			})
			return;
		}
		let regex = /^[1-9]\d*$/;
		var reg = /(^[1-9][0-9]*$)|(^[1-9][0-9]*\.\d{0,2}$)|^0(?!\d)\.?\d{0,2}$|^[1-9]?$/;
		let error = false;
		if (other == 'patWeight' || other == "temperature") {
			if (!reg.test(value)) {
				error = true
			}

		} else {
			if (!regex.test(value)) {
				error = true
			}
		}
		// if(regex.test(value)){
		//     if(other == "patWeight" || other == "temperature"){
		//         error = false;
		//     }else{
		//         error= false;
		//     }
		// }else{
		//     error = true;
		// }
		// // if (value != "") {
		// //     if (other !== "patWeight") {
		// //         if (regex.test(value)) {
		// //         error = true;
		// //         }
		// //     }else if(other !== "temperature"){
		// //         if (regex.test(value)) {
		// //             error = true;
		// //             }
		// //     }else {
		// //       error = false ;
		// //     }
		// // }
		if (error) {
			this.setState({
				msgVisible: true,
				msgType: 'warn',
				msg: "输入非法字符!",
				msgDelayed: true,
			})
			return;
		}
		this.setState({
			[other]: value,
		})
	}

	// 阻止默认事件
	handleStopPropagation = (e) => {
		if (typeof e == 'object') {
			e.stopPropagation();
		}
	}

	//添加历史诊断
	addHistory(diagList, e) {
		var firstFlag = 0
		let dataSource = this.state.dataSource;
		const dataSourceLength = this.state.dataSource.length - 1;
		const lastDiag = dataSource[dataSource.length - 1]; //最后一条诊断有无填写信息
		let deleteLast = false;
		if (!Util.isEmpty(lastDiag)) {
			if ((Util.isEmpty(lastDiag.diagDesc)) && (Util.isEmpty(lastDiag.id)) && (Util.isEmpty(lastDiag.descripts))) {
				dataSource.splice(dataSource.length - 1, 1);
				deleteLast = true;
			}
		} else {
			deleteLast = true;
		}
		let editData = this.state.editData;
		let newdataSource = this.state.dataSource;
		for (var i = 0; i < diagList.length; i++) {
			let diagRecord = {};
			Object.assign(diagRecord, diagList[i]);
			// diagRecord = diagList[i]; && diag.diagTypeID == dataSource[this.state.indexTable].diagTypeID
			var unFind = true;
			for (var j = 0; j < dataSource.length; j++) {
				const diag = dataSource[j];
				if (((diag.diagID + "") === (diagRecord.diagID + "")) && (diagRecord.diagID !== "") && diag.diagTypeID == this.state.diagTypeDefID) {
					unFind = false;
				}
				if (((diag.descripts + "") === (diagRecord.descripts + "")) && (diagRecord.descripts !== "") && diag.diagTypeID == this.state.diagTypeDefID) {
					unFind = false;
				}
			}
			//如果是从诊断模板添加没有诊断类别等信息，赋默认值
			if ((Util.isEmpty(diagRecord.diagCMarkID))) diagRecord.diagCMarkID = this.state.CMark;
			if ((Util.isEmpty(diagRecord.mainDiagID))) diagRecord.mainDiagID = this.state.mainDiag;
			if ((Util.isEmpty(diagRecord.diagTypeID))) diagRecord.diagTypeID = this.state.diagTypeDefID;
			else {
				diagRecord.diagTypeID = diagRecord.diagTypeID + "";
			}
			if ((Util.isEmpty(diagRecord.catID))) diagRecord.catID = this.state.diagCatDefID;
			if ((Util.isEmpty(diagRecord.diagStatusID))) diagRecord.diagStatusID = this.state.diagStatusDefID;
			if (!(Util.isEmpty(diagRecord.CMark))) {
				diagRecord.diagCMarkID = diagRecord.CMark;
			}
			if (dataSourceLength == 0 && firstFlag == 0 && diagList[i].mainFlag == "Y") {
				diagRecord.mainDiagID = "Y"
				firstFlag = firstFlag + 1
			}
			diagRecord.editable = true;
			if ((Util.isEmpty(diagRecord.diagCMark))) {
				if (diagRecord.diagCMarkID == "Y") {
					diagRecord.diagCMark = "中医";
				} else {
					diagRecord.diagCMark = "西医";
				}
			}
			if (unFind) {
				diagRecord.index = newdataSource.length + 1;
				diagRecord.id = "";
				newdataSource.push(diagRecord);
				editData.push(newdataSource.length - 1)
			} else {
				message.warn("诊断:" + diagRecord.diagDesc + " " + diagRecord.descripts + "重复添加!");
			}
		}

		this.setState({
			nodeId: [],
			editData: editData,
			dataSource: newdataSource
		}, () => {
			if (deleteLast) {
				this.addDiag("1");
			}
		})

	}

	//关闭诊断模板
	onCloseDiagTemplateModal = () => {
		this.setState({
			diagTemplateVisible: false,
		})
	}

	//添加诊断到模板
	onShowDiagTemplateModal = () => {
		const ids = this.state.ids;
		if (ids.length === 0) {
			this.setState({
				msgVisible: true,
				msgType: 'warn',
				msg: "请先选择要添加到模板的诊断!",
				msgDelayed: true,
			})
			return
		}
		let addToTemplateDiag = [];
		const dataSource = this.state.dataSource;
		var syflag = false;
		let index = 1;
		for (var i = 0; i < ids.length; i++) {
			let id = ids[i] - 1;
			if ((!Util.isEmpty(dataSource[id].diagID)) || (!Util.isEmpty(dataSource[id].descripts))) {
				let obj = {};
				obj.diagID = dataSource[id].diagID;
				if (dataSource[id].diagCMarkID == "Z") {
					syflag = true;
				}
				obj.seqNo = index;
				obj.descripts = dataSource[id].descripts;
				addToTemplateDiag.push(obj);
				index++;
			}
		}
		if (syflag) {
			message.warn("不能维护证型到诊断模板", this.state.userData && this.state.userData.messageTime);
			return;
		}
		if (addToTemplateDiag.length === 0) {
			this.setState({
				msgVisible: true,
				msgType: 'warn',
				msg: "选择的行未填写诊断信息!",
				msgDelayed: true,
			})
			return
		}
		this.setState({
			diagTemplateVisible: true,
			diagTemplate: addToTemplateDiag,
		})
	}

	//加载诊断模版
	loadTemplate() {
		var templateTree = []
		this.state.templetTreeData && this.state.templetTreeData.map((item, index) => {
			this.loadSunTemplate(item.data)
		})
		return templateTree
	}

	//展开诊断模板节点
	loadSunTemplate(data) {
		var sunData = []
		data && data.map((item, index) => {
			sunData.push(<TreeNode title={(item.title || item.descripts || '') + "" + (item.diagDesc || "") + (item.alias ? "(" + item.alias + ")" : "")} nodeId={item.id}
				key={item.index + ""} disabled={this.state.disBtn == 'N'}>
				{this.loadSunTemplate(item.data)}
			</TreeNode>)
		})
		return sunData
	}

	//初始化
	loadEventKye() {
		let treeData = [];
		if (!Util.isEmpty(this.state.templetTreeData)) {
			var source = this.state.templetTreeData;
			for (var i = 0; i < source.length; i++) {
				if (source[i].default == 'Y' || source[i].id == this.state.radioValue) {
					treeData = source[i].data
				}
			}
		}
		var expandedKeys = []
		if (!Util.isEmpty(treeData)) {
			for (var i = 0; i < treeData.length; i++) {
				expandedKeys.push(treeData[i].index)
			}
			this.setState({ expandedKeys: expandedKeys })
		}
	}

	//诊断模板双击事件
	onDiagTemplateDblClick(record, data) {
		const key = data.props.eventKey.split("||");  //点击节点的Key值
		if (key.length === 0) return;
		let datakey;
		let templetTreeData = [];
		if (key.length === 1) {
			//点击跟节点
			templetTreeData = [].concat(this.state.templetTreeData[key[0]]);
		}
		if (key.length === 2) {
			//点击模板主表
			templetTreeData = [].concat(this.state.templetTreeData[key[0]].data[key[1]]);
		}
		if (key.length === 3) {
			//点击模板子表
			templetTreeData = [].concat(this.state.templetTreeData[key[0]].data[key[1]].data[key[2]]);
		}
		var diagList = [];
		this.getDiagData(templetTreeData[0], diagList);
		diagList = [].concat(diagList);
		this.addHistory(diagList);
	}

	getDiagData(templateData, diagList) {
		if (templateData.data) {
			templateData.data.map((item, index) => {
				if (item.data) {
					this.getDiagData(item, diagList)
				} else {
					diagList.push(item);
				}
			})
		} else {
			diagList.push(templateData);
		}
	}

	//诊断模板点击复选框
	checkTreeNode(e, data) {
		this.setState({
			nodeId: e
		})
	}

	onExpandIcon(e) {
		this.setState({
			expandedKeys: e
		})
	}

	//点击树节点展开树
	onExpand(data, e) {
		var expandedKeys = [] = this.state.expandedKeys;
		var keys = []//该值用于点击同一节点时不会关闭其他的树节点
		if (!Util.isEmpty(e.props.children)) {//判断其点击节点下有子节点
			if (!Util.isEmpty(expandedKeys)) {
				for (var i = 0; i < expandedKeys.length; i++) {
					if (e.props.eventKey !== expandedKeys[i]) {//用于将所有的树节点展开
						keys.push(expandedKeys[i])
						this.setState({
							expandedKeys: expandedKeys.concat([e.props.eventKey])
						})
					} else {
						this.setState({//当点击的是同一节点时，控制展开，关闭
							expandedKeys: keys
						})
					}
				}
			} else {
				this.setState({
					expandedKeys: [e.props.eventKey]
				})
			}
		}
	}

	//批量添加诊断模板数据
	onAddDiag = () => {
		const nodeId = this.state.nodeId;
		var diagList = [];
		for (var i = 0; i < nodeId.length; i++) {
			var templetTreeData = {};
			const key = nodeId[i].split("||");  //点击节点的Key值
			if (key.length !== 3) continue;
			Object.assign(templetTreeData, this.state.templetTreeData[key[0]].data[key[1]].data[key[2]]);
			diagList.push(templetTreeData);
		}
		diagList = [].concat(diagList);
		this.addHistory(diagList);

	}

	//模板搜索框改变
	onTemplateChange = (e) => {
		this.setState({
			templateDesc: e.target.value,
		})
	}

	//模板搜过框回车事件
	onTemplateEnter = () => {
		this.initTempletTreeData();
	}

	//切换诊断面板
	onTabsChange = (activeKey) => {
		this.setState({
			activityTabs: activeKey
		})
	}

	//取消弹框显示，焦点问题
	handleFocus() {
		scrollCount = 0;
		this.setState({
			selectData: []
		}, () => {
			if ((this["diagDesc" + this.state.selectIndex]) && (this["diagDesc" + this.state.selectIndex].current)) {
				this["diagDesc" + this.state.selectIndex].current.focus()
			}
		})
	}

	showCommonTableModal(index, data, name, e) {
		if (e.keyCode == '13') {
			if (data[name]) {
				this.setState({
					isShowCommonTableModal: true,
					searchData: data,
					search: "1",
				}, () => {
					this.loadSelectData(data[name], '', '')
					this.child.showModal();
				})
			}
		}
	}

	// 操作弹框
	onClickRowPublic = (record, index) => {
		return {
			onDoubleClick: () => {
				if (this.state.changename == "ICDDesc") {
					this.ICDRowClick(record, index)
				} else {

					this.rowClick(record, index)
				}
			},
			onClick: () => {
				if (this.state.selectedMode == "Y") {
					if (this.state.changename == "ICDDesc") {
						this.ICDRowClick(record, index)
					} else {

						this.rowClick(record, index)
					}
				} else {

					this.setState({
						rowMedID: record.id
					})
				}
			}
		}
	}

	setRowClassNamePublic = (record) => {
		return record.id === this.state.rowMedID ? 'clickRowStyle' : '';
	}

	onRef = (ref) => {
		this.child = ref;
	}

	//诊断名称获取焦点时触发
	onDiagDescFocus = (index, e) => {
		this.setState({
			selectIndex: index,
		})
	}

	ChangeRatio = () => {
		var ratio = 0;
		var screen = window.screen;
		var ua = navigator.userAgent.toLowerCase();

		if (window.devicePixelRatio !== undefined) {
			ratio = window.devicePixelRatio;
		}
		else if (~ua.indexOf('msie')) {
			if (screen.deviceXDPI && screen.logicalXDPI) {
				ratio = screen.deviceXDPI / screen.logicalXDPI;
			}

		}
		else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
			ratio = window.outerWidth / window.innerWidth;
		}

		if (ratio) {
			ratio = Math.round(ratio * 100);
		}
		return ratio;
	}

	//列修改为input框，change事件处理
	handleSearchInput(name, index, data, e) {
		var dataSource = this.state.dataSource;
		let top = document.getElementById(name + "-input" + index).getBoundingClientRect().top + 40
		let left = document.getElementById(name + "-input" + index).getBoundingClientRect().left;
		let windowHeight = window.innerHeight - 58;
		let rate = this.ChangeRatio();
		let modelHeight = this.state.modelHeight;
		let oldTop = top;
		if ((top + modelHeight + 30) > windowHeight) {
			top = top - 330 - 40;
			if (top < 58) {
				top = 58;
				if ((windowHeight - oldTop) > oldTop) {
					top = oldTop;
					if ((windowHeight - oldTop) < modelHeight) {
						modelHeight = windowHeight - oldTop;
					}

				} else {
					if ((oldTop - 58) < modelHeight) {
						modelHeight = oldTop - 58 - 40;
					} else {
						top = oldTop - 40 - modelHeight;
					}
				}
			}
		} else {
			if ((windowHeight - top) < modelHeight) {
				//剩余位置小于默认的弹框高度
				if ((windowHeight - top) > top) {
					//下半部分高度大于上半部分
					modelHeight = windowHeight - top - 40;
				} else {
					//下半部分小于上半部分
					if ((windowHeight - top) > modelHeight) {
						//上半部分高度大于默认高度
						top = top - 330 - 40;
					} else {
						//上半部分高度小于默认高度
						modelHeight = windowHeight - 40 - oldTop;
						top = 58;
					}
				}
			}
		}
		//modelHeight = rate / 100 * modelHeight;
		top = top + "px";
		left = left + "px";
		var value = e.target.value;
		dataSource[index][name] = value;
		this.setState({
			indexTab: index,
			top: top,
			left: left,
			searchData: data,
			selectIndex: index,
			dataSource: dataSource,
			changename: name,
			changeValue: value,
			diseasesID: data.diseasesID,
			selectData: [],
			total: 0,
			modelHeight: modelHeight,
			page: 1,
		})
		if (value.length >= 2) {
			this.loadSelectData(value, '', '')
		} else {
			this.setState({
				selectData: [],
				total: 0,
				page: 1,
			})
		}
		document.addEventListener('elementTable', this.loadListener)
	}

	handleOnKeydown(e) {
		var e = window.event || e;
		let scroll_height = document.getElementsByClassName('clickRowStyle')[0] ? document.getElementsByClassName('clickRowStyle')[0].clientHeight : 26;
		if (scrollCount < 0) {
			scrollCount = 0
		}
		let id = '';
		let oneArr = this.state.selectData && this.state.selectData.length > 0 ? this.state.selectData : [];
		switch (e.keyCode) {
			case 13:
				if ((this.state.rowMedID) && (e.target.nodeName != "INPUT")) {
					let obj = {}
					for (var i = 0; i < oneArr.length; i++) {
						if (oneArr[i].id === this.state.rowMedID) {
							obj = i > 0 ? oneArr[i] : oneArr[0];
							break;
						}
					}
					if (this.state.changename == "ICDDesc") {
						this.ICDRowClick(obj)
					} else {

						this.rowClick(obj)
					}
				}
				break;
			case 38: //上
				if (this.state.rowMedID) {
					for (var i = 0; i < oneArr.length; i++) {
						if (oneArr[i].id === this.state.rowMedID) {
							id = i > 0 ? oneArr[i - 1].id : oneArr[0].id;
							break;
						}
					}
					this.setState({ rowMedID: id }, () => {
						scrollCount -= document.getElementsByClassName('clickRowStyle')[0].clientHeight
						// var gundong = document.getElementById("gundong");
						// gundong.scrollTop = gundong.scrollTop - scroll_height;
						var gundong = document.getElementsByClassName('ant-table-body')[1]
						gundong.scrollTop = gundong.scrollTop - scroll_height;
					})
				} else {
					this.setState({ rowMedID: oneArr[0].id })
				}
				break;
			case 40: //下
				if (this.state.rowMedID) {
					for (let i = 0; i < oneArr.length; i++) {
						if (oneArr[i].id === this.state.rowMedID) {
							id = i + 1 >= oneArr.length ? oneArr[oneArr.length - 1].id : oneArr[i + 1].id;
							break;
						}
					}
					this.setState({ rowMedID: id }, () => {
						// var gundong = document.getElementById("gundong");
						// gundong.scrollTop = gundong.scrollTop + scroll_height;
						scrollCount += document.getElementsByClassName('clickRowStyle')[0].clientHeight
						var gundong = document.getElementsByClassName('ant-table-body')[1]
						if (scrollCount > 260) {
							gundong.scrollTop = gundong.scrollTop + scroll_height;
						}
					})
				} else {
					this.setState({ rowMedID: oneArr[0].id })
				}
				break;
		}
	}

	//组件权限编辑器
	onColumnRef = (ref) => {
		this.columnRef = ref;
	}

	//隐藏导航栏
	hideModule() {
		this.setState({
			moduleStatus: true
		})
	}

	showModule() {
		this.setState({
			moduleStatus: false
		})
	}

	//选择诊断模板
	changeRadio(e) {
		this.setState({
			radioValue: e.target.value
		}, () => {
			this.loadEventKye()
		})
	}

	// 是否需测血压
	ifNeedMeasuringBP = () => {
		let data = {
			params: [{
				patID: recordData ? recordData.patID : '',
				admID: recordData ? recordData.admID : ''
			}]
		};
		$http.post('urlDeault', this, {
			code: "03050144",
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					this.setState({
						measureFlag: res.result,
						measureAge: res.measureAge
					})
				}
			},
			error: function (error) {
				message.error('失败：' + error);
			}
		});
	}

	//渲染门诊挂号评估单数据
	loadSheetData() {
		var { assmentSheetData, } = this.state;
		var assmentSheetOption = []
		var listData = []
		var selectData = []
		assmentSheetData && assmentSheetData.map((item, index) => {
			listData = item.field
			assmentSheetOption.push(<TabPane key={item.id} value={item.id} tab={item.title}>
				<div style={{ height: '136px', overflow: 'auto' }}>
					{/* <h4 style={{ marginLeft: 5, color: '#007AFF' }}>{item.title}</h4> */}
					{listData && listData.map((data, code) => {
						if (data.fieldTypeCode == 'Select' || data.fieldTypeCode == 'SelectTags') {
							selectData = data.fieldDataList
						}
						return <Col key={code} span={7} style={{ marginLeft: 10, display: 'flex', marginTop: 10 }}>
							<div style={{ width: '29%', textAlign: 'right', marginTop: 5 }}>{data.descripts}：</div>
							{data.fieldTypeCode == 'SelectTags' || data.code === 'OD' || data.code === 'OS' || data.code === 'ODIOP' || data.code === 'OSIOP' || data.code === 'ODOstiole' || data.code === 'OSOstiole' ? (
								<AutoComplete
									allowClear
									placeholder="请选择"
									style={{ width: '70%' }}
									defaultActiveFirstOption={false}
									dataSource={React.$SelectOptions(selectData, 'descripts')}
									disabled={!(item?.docSaveFlag === 'Y')}
									value={Array.isArray(data.value) && data.value.length > 0 ? data.value[0] : [data.value || undefined]}
									onChange={(e) => this.handleChangeCommonSelect(data, e)}
								>
								</AutoComplete>
							) : (data.fieldTypeCode == 'Select' ? (
								<Select
									allowClear
									placeholder="请选择"
									style={{ width: '70%' }}
									disabled={!(item?.docSaveFlag === 'Y')}
									value={data.value}
									onChange={(e) => this.handleChangeCommonSelect(data, e)}
								>
									{selectData && selectData.map((source, ids) => {
										return <Option key={ids} value={source.descripts}>{source.descripts}</Option>
									})}
								</Select>
							) : (
								<Input allowClear style={{ width: '70%' }} disabled={!(item?.docSaveFlag === 'Y')} value={data.value} onChange={this.changeCommonInput.bind(this, data)} />
							))}
						</Col>
					})}
					{item?.docSaveFlag === 'Y' ? <Button style={{ marginTop: 10 }} type='primary' onClick={this.handleSaveMeg.bind(this)}>保存</Button> : ''}
				</div>
			</TabPane>)
		})
		return assmentSheetOption
	}

	handleChangeCommonSelect(data, e, type) {
		console.log('data', data, e)
		if (type === "tags") {
			let newValue = [];
			if (e && e.length > 0) {
				newValue.push(e[e.length - 1]);
			}
			data['value'] = newValue;
		} else {
			data['value'] = e;
		}
		this.setState({})
	}

	changeCommonInput(data, e) {
		data['value'] = e.target.value
		this.setState({})
	}

	changeActiveKey(e) {
		this.setState({
			activeKey: e
		})
	}

	//保存
	handleSaveMeg() {
		var { assmentSheetData } = this.state;
		var sourceOption = []
		var fieldData = []
		var sources = {}
		for (var i = 0; i < assmentSheetData.length; i++) {
			if (this.state.activeKey == assmentSheetData[i].id) {
				fieldData = assmentSheetData[i].field
				sources = {
					userID: this.state.userData.userID,
					admID: !Util.isEmpty(this.state.recordData) ? this.state.recordData.admID : '',
					id: assmentSheetData[i].regValuationFormID,
					regValuationID: assmentSheetData[i].id,
				}
			}
		}

		for (var j = 0; j < fieldData.length; j++) {
			sourceOption.push({
				regValuationFormDetailID: fieldData[j].regValuationFormDetailID,
				fileID: fieldData[j].fileID,
				fileValue: fieldData[j].value,
			})
		}

		var data = [{
			...sources,
			files: sourceOption
		}]

		var params = {
			params: data
		}
		$http.post('urlDeault', this, {
			code: "03040030",
			data: params,
			success: function (res) {
				if (res.errorCode == '0') {
					message.success('保存成功！')
					this.loadConfigAssessmentSheet()
				}
			}
		});
	}

	/**
	 * 复制为入院/出院诊断
	 */
    copyDiagnosis = (type) => {
		if (this.state.ids.length == 0) {
			message.warn("请选择要复制的诊断");
			return;
		}
        let copyDiagTypeID = ""; //诊断类型ID

		this.state.typeData.map((item) => {
            if (item.code == type) {
                copyDiagTypeID = item.id;
            }
		})
		var copyDiag = [];
		var { dataSource } = this.state;
		var index = dataSource.length;
		dataSource.splice(index - 1, 1)
		this.state.ids.map((item) => {
			if (dataSource[item - 1] && dataSource[item - 1].diagTypeCode && dataSource[item - 1].diagTypeCode == "DIS") {
				message.warn(dataSource[item - 1].diagDesc + "已经是"+ type === 'ADD' ? "入院诊断": "出院诊断" +"不能复制！");
			} else {
				var copyItem = {};
				for (var key in dataSource[item - 1]) {
					copyItem[key] = dataSource[item - 1][key];
				}
				copyItem.diagTypeCode = type;
				copyItem.diagTypeDesc = type === 'ADD' ? "入院诊断": "出院诊断";
				copyItem.diagTypeID = copyDiagTypeID;
				copyItem.id = "";
				copyItem.index = index + 1;
				copyItem.editable = true;
				copyDiag.push(copyItem);
				index = index + 1;
			}
		})
		dataSource = [...dataSource, ...copyDiag];
		this.setState({
			dataSource: dataSource
		}, () => {
			this.addDiag("1");
		})
	}

	/**
	 * @ByShizi: 科室切换
	 * Create 2022-12-01
	 * */
	handleMenuItemChange = item => {
		this.setState({ currentLocData: item }, () => {
			this.initTempletTreeData();
		});
	}

	render() {
		const { page, total, top, left, selectData, currentLocData, userData, userLoginLoc } = this.state;
		const rowSelection = {
			width: '18px',
			onChange: (selectedRowKeys, selectedRows) => {
				this.setState({ ids: selectedRowKeys })
			},
			selectedRowKeys: this.state.ids
		}
		let param = {
			width: '800px',
			height: this.state.modelHeight,
			top: top,
			left: left,
			bordered: true,
			columns: this.state.searchData.diagCMarkID == "Z" ? this.state.SyndromeTypeColumns : this.state.changename == 'ICDDesc' ? this.state.ICDColumns : this.state.dialogColumns,
			data: selectData,
			isOnRow: true,
			TableClassName: 'tab-placeholder',
			rowClassName: true,
			showPagination: true,
			page,
			total,
			x: 600,
		}

		const subMenu = [];
		this.state.historyDiag.map((item, index) => {
			subMenu.push(
				<SubMenu
					key={index}
					disabled={this.state.disBtn == 'N'}
					onTitleClick={this.onLocClick}
					title={(
						<div style={{
							width: "100%",
							overflow: 'hidden',
							textOverflow: 'ellipsis',
							whiteSpace: 'nowrap',
						}} >
							<Icon type='plus' onClick={this.addHistory.bind(this, item.diagList)} style={{ color: '#409EFF', padding: '0px' }} />
							{/* <Tooltip title={item.admDate + " " + item.admLocDesc}>
                                {item.admDate + " " + item.admLocDesc}
                            </Tooltip> */}
							{item.admDate + " " + item.admLocDesc}
						</div>)} >
					{
						item.diagList.map((diagItem, diagIndex) => {
							return (
								<Menu.Item key={index + "." + diagIndex}
								>
									<div
										style={{
											width: "100%",
											overflow: 'hidden',
											textOverflow: 'ellipsis',
											whiteSpace: 'nowrap',
										}}
										onDoubleClick={this.addHistory.bind(this, [diagItem])}
									>
										<Tooltip title={diagItem.diagDesc + " " + diagItem.descripts}>
											{diagItem.diagDesc + " " + diagItem.descripts}
										</Tooltip>
									</div>
								</Menu.Item>
							)
						})
					}
				</SubMenu >
			)
		})
		//诊断类型 初诊  复诊
		let diagRadio = [];
		this.state.medicalType.map((item) => {
			diagRadio.push(<Radio value={item.id} key={item.id}>{item.descripts}</Radio>);
		})
		let tabsItem = [];
		this.state.templetTreeData && this.state.templetTreeData.map((item, index) => {
			tabsItem.push(
				<Radio value={item.id} key={index}>{item.title} </Radio>
			);
		})
		let treeData = [];
		// if (this.state.templetTreeData.length > 0) {
		//     treeData = this.state.templetTreeData[this.state.radioValue].data;
		// }
		if (!Util.isEmpty(this.state.templetTreeData)) {
			var source = this.state.templetTreeData;
			for (var i = 0; i < source.length; i++) {
				if (source[i].id == this.state.radioValue) {
					treeData = source[i].data
				}
			}
		};
		const locMenuData = (
			<Menu>
				{userLoginLoc && userLoginLoc.map((item, index) => {
					return (
						<Menu.Item key={index} onClick={() => this.handleMenuItemChange(item)}>
							<span>{item.locDesc}</span>
						</Menu.Item>
					)
				})}
			</Menu>
		);
		return <div className='doctor-diag-body' style={{ height: store.getState().tableHeight.y + 165 + 'px' }}>
			<ColumnAuthoritysModel
				clientWidth='800px'
				compontName="DiagTable"
				configType="C"
				onRef={this.onColumnRef}
				reloadData={this.loadColumn}
			/>
			{this.state.moduleStatus ?
				<Card style={{
					width: '20px', height: '100%', float: 'left', background: '#f5f4f4'
					, cursor: 'pointer', paddingTop: 200, textAlign: 'center'
				}} hoverable={true} onClick={this.showModule.bind(this)}>
					<div className='change-card-icon-show'><Tooltip title={this.display('DiagTableshowTemplate')}>
						<Icon type='double-right' style={{ fontSize: '18px' }} /></Tooltip></div>{this.display('DiagTableshowTemplate')}</Card> :
				<Card
					style={{ float: 'left', width: '16.91%', overflow: 'auto', height: '100%' }}
					hoverable={true}
					title={<span style={{ marginLeft: 10 }}><img src={doctorOrder} style={{ marginRight: 5 }} />{this.display('DiagTablediagnosticTemplate')} </span>}
					bodyStyle={{ height: 'calc(100% - 42px)', position: 'relative' }}
					extra={(
						<Dropdown overlay={locMenuData}>
							<span className="span" style={{ color: '#333' }}>
								{currentLocData?.locDesc || userData?.locDesc}
								<Icon type="down" />
							</span>
						</Dropdown>
					)}
				>
					<Input placeholder={this.display('DiagTabletemplateSearch')} style={{ margin: '5px', width: '93%' }}
						prefix={<Icon type="search" style={{ color: 'rgba(0,0,0,.25)' }} />}
						onPressEnter={this.onTemplateEnter}
						value={this.state.templateDesc} onChange={this.onTemplateChange} />
					<div className='diagTemplateRadio'>
						<div style={{ height: '100%', width: 'calc(90% - 10px)', float: 'left', marginLeft: '10px' }}>
							<Radio.Group value={this.state.radioValue}
								onChange={this.changeRadio.bind(this)}>
								{tabsItem}
							</Radio.Group>
						</div>
						<div onClick={this.hideModule.bind(this)} className='hideTemplate'>
							<Tooltip title={'隐藏诊断模板'}>
								<Icon type='double-left' style={{ fontSize: '18px' }} />
							</Tooltip>
						</div>
					</div>
					<div style={{ height: 'calc(100% - 74px)', overflow: 'hidden', paddingBottom: '36px' }}>
						<div style={{ height: '100%', overflowY: 'auto', overflowX: 'hidden' }}>
							<Tree
								checkable defaultExpandAll={false}
								checkedKeys={this.state.nodeId}
								onClick={this.onExpand.bind(this)}
								onExpand={this.onExpandIcon.bind(this)}
								onCheck={this.checkTreeNode.bind(this)}
								expandedKeys={this.state.expandedKeys}
								onDoubleClick={this.onDiagTemplateDblClick.bind(this)}
							>
								{this.loadSunTemplate(treeData)}
							</Tree>
						</div>
					</div>
					<div style={{ position: 'absolute', bottom: 0, left: 0, width: '100%', padding: '0 12px' }}>
						{/* 批量添加 */}
						<Button block onClick={this.onAddDiag.bind(this)}>{this.display('DiagTablebatchesAdd')}</Button>
					</div>
				</Card>
			}
			<Card style={{ float: 'right', width: '15.09%', height: '100%' }}
				title={
					<div>
						<span className='scheduling-title-border' style={{ marginLeft: '10px' }}></span>
						<span style={{ marginLeft: 5, color: '#666666' }}>{this.display('DiagTablehisDiagList')}</span>
					</div>
				}
				bodyStyle={{ height: 'calc(100% - 35px)' }}>
				<div style={{ minHeight: '40px', lineHeight: '30px', width: '100%', padding: '5px', borderBottom: '1px solid #cccccc' }}>
					<Radio.Group value={this.state.admType} onChange={this.onAdmTypeChange}>
						<Radio value="A">{this.display('DiagTableAllDiag')}</Radio>
						<Radio value="I">{this.display('DiagTableInDiag')}</Radio>
						<Radio value="O">{this.display('DiagTableOPDiag')}</Radio>
					</Radio.Group>
				</div>
				<div style={{ height: 'calc(100% - 40px)', overflow: 'hidden' }}>
					<div style={{ height: '100%', overflowY: 'auto', overflowX: 'hidden' }}>
						<Menu mode="inline" theme="light">
							{subMenu}
						</Menu>
					</div>
				</div>
			</Card>
			<Card
				style={{ float: 'right', width: this.state.moduleStatus ? 'calc(84.91% - 33px)' : 'calc(68% - 12px)', margin: '0 6px', height: '100%' }}
				bodyStyle={{ height: '100%' }}>
				<div className="diagTitle">
					<span className='scheduling-title-border' style={{ marginLeft: '10px' }}></span>
					<span style={{ marginLeft: 5, }}>{this.display('DiagTablediagInfo')}</span>
				</div>
				{/* <div style={{ margin: '14px 10px 12px 10px', border: "1px solid rgba(225,225,225,1)", height: this.state.admInfo.admTypeCode != 'W' ? 'calc(100% - 272px)' : 'calc(100% - 62px)' }}> */}
				<div style={{ margin: '14px 10px 12px 10px', border: "1px solid rgba(225,225,225,1)", height: (this.state.admInfo.admTypeCode == 'W' || this.state.admInfo.admTypeCode == 'I') ? 'calc(100% - 62px)' : 'calc(100% - 272px)' }}>
					<div style={{ display: 'flex', height: '34px', lineHeight: '34px', padding: '0 20px' }}>
						<span style={{ cursor: 'pointer' }}
							onClick={this.delDiag.bind(this)} >
							<Icon className='doctor-delete-splice' />
							<span className="btnText">{this.display('DiagTabledelete')}</span>
						</span><Divider type="vertical" />
						{/* <Button ghost icon="plus" style={{ color: '#409EFF', border: '0px' }} onClick={this.addDiag.bind(this, "0")} >添加</Button> */}
						<span style={{ cursor: 'pointer' }}
							onClick={this.handleUpSort.bind(this)} >
							<Icon className='doctor-up-splice' />
							<span className="btnText">{this.display('DiagTablemoveUp')}</span>
						</span><Divider type="vertical" />
						<span style={{ cursor: 'pointer' }}
							onClick={this.handleDownSort.bind(this)} >
							<Icon className='doctor-down-splice' />
							<span className="btnText">{this.display('DiagTablemoveDown')}</span>
						</span><Divider type="vertical" />
						<span style={{ cursor: 'pointer' }} onClick={this.onShowDiagTemplateModal.bind(this)} >
							<Icon className='doctor-plus-square-splice' />
							<span className="btnText">{this.display('DiagTableaddTemplate')}</span>
						</span><Divider type="vertical" />
						<Button type='primary' style={{ cursor: 'pointer' }} disabled={this.state.disBtn == 'N'}
							onClick={this.saveDiagnosisMsg.bind(this)} >
							{this.display('DiagTablesave')}
						</Button>
						<Divider type="vertical" />
                        <Button type='primary' style={{ cursor: 'pointer' }} disabled={this.state.disBtn == 'N'} onClick={this.copyDiagnosis.bind(this, 'ADD')} >
                            {this.display('DiagTablecopyIn')}
                        </Button>
                        <Divider type="vertical" />
						<Button type='primary' style={{ cursor: 'pointer' }} disabled={this.state.disBtn == 'N'} onClick={this.copyDiagnosis.bind(this, 'DIS')} >
							{this.display('DiagTablecopyOut')}
						</Button>
						<Divider type="vertical" />
					</div>
					<Table columns={this.state.diagColumns.length > 0 ? this.state.diagColumns : this.columns} style={{ height: 'calc(100% - 34px)', width: '100%' }}
						className="diagTable"
						dataSource={this.state.dataSource}
						loadData={this.loadData.bind(this)}
						rowSelection={rowSelection}
						scroll={{ y: 'calc(100% - 46px)', x: this.state.diagColumnsWidth }}
						bordered
						rowKey={(data) => {
							return data.index
						}}
						onRow={(record, index) => ({ onDoubleClick: (e) => { this.onDiagRowClick(record, index, e); } })}
						pagination={false}
						onHeaderRow={column => {
							return {
								onDoubleClick: () => {
									this.columnRef.onOpenModel();
								}
							};
						}}
					>

					</Table>
				</div>
				{/* <div className="otherTitle" style={{ display: this.state.admInfo.admTypeCode != 'W' ? '' : 'none' }}> */}
				<div className="otherTitle" style={{ display: (this.state.admInfo.admTypeCode == 'W' || this.state.admInfo.admTypeCode == 'I') ? 'none' : '' }}>
					<span className='scheduling-title-border' style={{ marginLeft: '10px' }}></span>
					<span style={{ padding: '0 5px' }}>{this.display('DiagTableotherInfo')}</span>
				</div>
				{!Util.isEmpty(this.state.assmentSheetData) ?
					// <div style={{ color: '#000000', width: '100%', height: '174px' }} className='config-out-sheet' style={{ display: this.state.admInfo.admTypeCode != 'W' ? '' : 'none' }}>
					<div style={{ color: '#000000', width: '100%', height: '174px', display: (this.state.admInfo.admTypeCode == 'W' || this.state.admInfo.admTypeCode == 'I') ? 'none' : '' }} className='config-out-sheet'>
						<Tabs activeKey={this.state.activeKey} size='small' onChange={this.changeActiveKey.bind(this)}>
							{this.loadSheetData()}
						</Tabs>
					</div> : null
				}
			</Card>
			<Message
				title={this.state.msgTitle}
				visible={this.state.msgVisible}
				onOk={this.onMsgOk}
				onCancel={this.onMsgCancel}
				okText={this.state.msgOkText}
				cancelText={this.state.msgCancelText}
				msg={this.state.msg}
				handleMsg={this}
				type={this.state.msgType}
				footer={this.state.msgFooter}
				delayed={this.state.msgDelayed}
			/>
			<AddDiagTemplateModal
				visible={this.state.diagTemplateVisible}
				handleThis={this}
				onCancel={this.onCloseDiagTemplateModal}
				diagList={this.state.diagTemplate}
				templetType={this.state.templetType}
			/>

			{/**列input框新表格弹框 */}
			<div
				tabIndex={1}
				onKeyDown={this.handleOnKeydown.bind(this)}
				style={{ outline: 'none' }}
			>
				<ShowCommonTableModal
					loading={this.state.loading}
					onClickRowPublic={this.onClickRowPublic}
					handleFocus={this.handleFocus.bind(this)}
					setRowClassNamePublic={this.setRowClassNamePublic}
					param={param}
					onRef={this.onRef}
					id="gundong"
					search={this.state.search}
					compilePage={this.changePageSize.bind(this)}>
				</ShowCommonTableModal></div>
			<InfectiousModel
				onRef={this.onInfectiousRef}
				reportID=''
				diseaseID={this.state.diseaseID}
				saveDiag={this.saveDiagnosisMsg}
			/>
		</div >
	}
};

export default DiagnosisStepPage;
